QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#820055 | #9897. Welcome Party | N_z_ | AC ✓ | 243ms | 67516kb | C++23 | 7.3kb | 2024-12-18 19:14:24 | 2024-12-18 19:14:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct time_helper{
#ifdef LOCAL
clock_t time_last;time_helper(){time_last=clock();}void test(){auto time_now=clock();std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;time_last=time_now;}~time_helper(){test();}
#else
void test(){}
#endif
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
int print_precision=10;bool print_T_endl=1;char print_between=' ';
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader;struct Writer;template<size_t id>struct read_tuple{template<typename...T>static void read(Reader&stream,std::tuple<T...>&x){read_tuple<id-1>::read(stream,x);stream>>get<id-1>(x);}};template<>struct read_tuple<0>{template<typename...T>static void read([[maybe_unused]]Reader&stream,[[maybe_unused]]std::tuple<T...>&x){}};template<size_t id>struct print_tuple{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){print_tuple<id-1>::print(stream,x);putchar(print_between);stream<<get<id-1>(x);}};template<>struct print_tuple<1>{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){stream<<get<0>(x);}};template<>struct print_tuple<0>{template<typename...T>static void print([[maybe_unused]]Writer&stream,[[maybe_unused]]const std::tuple<T...>&x){}};
struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename...T>Reader&operator>>(std::tuple<T...>&x){read_tuple<sizeof...(T)>::read(*this,x);return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}template<typename T1,typename T2>Reader&operator>>(std::pair<T1,T2>&x){*this>>x.first>>x.second;return *this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';
struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(const T&x){for(auto q:x){*this<<q;if(!is_class<decltype(q)>::value)*this<<print_between;}if(!is_class<typename T::value_type>::value&&print_T_endl)*this<<'\n';return *this;}template<typename...T>Writer&operator<<(const std::tuple<T...>&x){print_tuple<sizeof...(T)>::print(*this,x);if(print_T_endl)*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-print_precision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<print_precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<print_precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(const T&c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}template<typename T1,typename T2>Writer&operator<<(const std::pair<T1,T2>&x){*this<<x.first<<print_between<<x.second;if(print_T_endl)*this<<'\n';return *this;}Writer&operator<<(const std::string&str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<class Fun>class y_combinator_result{Fun fun_;public:template<class T>explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}template<class ...Args>decltype(auto) operator()(Args &&...args){return fun_(std::ref(*this), std::forward<Args>(args)...);}};template<class Fun>decltype(auto) y_combinator(Fun &&fun){return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));}
void init();void solve(int tc);
signed main()
{
init();int t=1;
cin>>t;
for(int tc=1;tc<=t;tc++)solve(tc);
}
void init()
{
}
void solve([[maybe_unused]]int tc)
{
int n,m;
cin>>n>>m;
vector<vector<int>>e(n+1);
for(int x=1;x<=m;x++)
{
int u,v;
cin>>u>>v;
e[u].emplace_back(v);
e[v].emplace_back(u);
}
vector<int>vis(n+1);
vector<vector<int>>ans;
int v0=0;
for(int x=1;x<=n;x++)
if(!vis[x])
{
priority_queue<int,vector<int>,greater<int>>pq;
ans.emplace_back();
pq.push(x);
vis[x]=1;
v0++;
while(!pq.empty())
{
int u=pq.top();
ans.back().emplace_back(u);
pq.pop();
for(auto v:e[u])
if(!vis[v])pq.push(v),vis[v]=1;
}
}
cout<<v0<<endl;
priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>>pq;
auto add=[&](int px,int py)
{
if(py<ans[px].size())pq.push({ans[px][py],px,py});
};
for(int x=0;x<ans.size();x++)
add(x,0);
while(!pq.empty())
{
auto [u,px,py]=pq.top();
pq.pop();
if(u!=1)cout<<' ';
cout<<u;
add(px,py+1);
}
cout<<endl;
}
/*
*/
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
2 4 3 1 2 1 3 1 4 4 2 1 2 3 4
output:
1 1 2 3 4 2 1 2 3 4
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 146ms
memory: 4480kb
input:
890 243 0 995 0 1734 0 2066 0 515 0 1583 0 873 0 1806 0 1624 0 510 0 618 0 1410 0 181 0 1283 0 784 0 1158 20000 653 308 962 139 748 254 642 332 1109 908 646 390 869 270 307 141 1125 937 9 289 272 151 195 781 465 793 509 599 1020 420 447 226 271 1034 880 901 1151 682 1090 800 1137 699 1011 273 1074 9...
output:
243 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
result:
ok 1780 lines
Test #3:
score: 0
Accepted
time: 162ms
memory: 3972kb
input:
19792 92 0 5 0 52 105 35 24 26 41 43 26 2 7 25 31 47 45 18 9 45 49 25 48 20 41 15 42 47 27 47 20 13 18 5 42 7 16 9 42 45 27 24 38 14 38 34 48 20 25 4 13 7 24 46 42 31 13 23 43 9 10 52 23 6 45 3 17 42 39 4 20 1 2 20 33 37 33 14 31 30 47 1 5 33 48 32 24 30 12 45 35 34 41 26 29 34 17 7 22 22 49 42 43 4...
output:
92 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 5 1 2 3 4 5 2 1 2 5 7 11 3 10 ...
result:
ok 39584 lines
Test #4:
score: 0
Accepted
time: 183ms
memory: 67516kb
input:
1 1000000 1000000 263045 635703 635703 552281 552281 283689 283689 376247 376247 795099 795099 55527 55527 431402 431402 553631 553631 321908 321908 823467 823467 797951 797951 921177 921177 688846 688846 955082 955082 66129 66129 448804 448804 900969 900969 332192 332192 521721 521721 360572 360572...
output:
1 1 209980 665346 579584 193431 638247 336374 576235 348073 749291 503485 130577 709696 709314 520328 790117 611983 581285 582879 771829 521972 346345 871665 827558 772812 559609 455233 591679 8232 31027 299918 258394 267967 51133 784172 497293 639550 495581 555269 624745 888785 404054 838575 574915...
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 243ms
memory: 14352kb
input:
29 47013 146506 26157 45309 2295 10357 42942 42561 42891 25643 23001 10483 44733 16789 12005 23079 44475 45109 44972 3147 6010 28049 37565 8085 27677 24581 41332 29813 40835 30513 44629 6573 15557 37997 11512 27171 20587 37715 431 36572 4717 25153 19597 42484 32138 4063 5461 43126 12038 19160 2375 4...
output:
95 1 128 246 483 545 915 1187 1206 1252 2248 2510 1118 1908 2076 2288 2357 2669 3511 3563 3700 3823 3840 4568 4924 4925 5867 5998 7218 8201 8244 8573 1621 3151 2189 6216 4594 6250 8618 8707 5577 6438 3102 6447 802 1570 1067 3625 4160 3387 4458 3287 4612 100 2149 404 2596 5173 3152 3175 281 1786 5383...
result:
ok 58 lines
Extra Test:
score: 0
Extra Test Passed