QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#340893 | #906. 强连通分量 | iorit# | AC ✓ | 192ms | 43484kb | C++14 | 1.3kb | 2024-02-29 13:53:07 | 2024-02-29 13:53:07 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
#define sl(n) strlen(n)
#define endline puts("")
#define pii pair<int , int>
#define pr_q priority_queue
#define debug puts("DEBUG.")
using namespace std;
const int N = 5e5 + 10;
const int inf = ~0u >> 2;
int n,m;
struct edge
{
int v,w,nxt;
}e[N];
int hd[N],cnt = 1;
void add(int u , int v)
{
++cnt,e[cnt].v = v;
e[cnt].nxt = hd[u],hd[u] = cnt;
}
int dfn[N],dfn_t,low[N];
int st[N],top,tot;
vector<int> vc[N];
bool vis[N];
void dfs(int u)
{
st[++top] = u,vis[u] = 1;
dfn[u] = low[u] = ++dfn_t;
bool fl = 0;
for(int i = hd[u];i;i = e[i].nxt)
{
int v = e[i].v;
if( vis[v] )
low[u] = min(low[u] , dfn[v] );
else if(!dfn[v] )
{
dfs(v);
low[u] = min(low[u] , low[v] );
}
}
if(low[u] == dfn[u] )
{
++tot;
int v;
do
{
v = st[top--],vis[v] = 0;
vc[tot].push_back(v);
}while(v != u);
}
}
int main()
{
cin >> n >> m;
for(int i = 1,u,v;i <= m;i++)
{
scanf("%d%d" , &u , &v),++u,++v;
if(u == v)
continue;
add(u , v);
}
for(int i = 1;i <= n;i++)
if( !dfn[i] )
dfs(i);
cout << tot << endl;
for(int i = tot;i;i--,endline)
{
printf( "%d " , vc[i].size() );
for(int x : vc[i] )
printf("%d " , x - 1);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15612kb
input:
6 7 1 4 5 2 3 0 5 5 4 1 0 3 4 2
output:
4 1 5 2 4 1 1 2 2 3 0
result:
ok OK
Test #2:
score: 0
Accepted
time: 166ms
memory: 43300kb
input:
500000 500000 389812 410922 255712 339244 274009 248522 347288 199231 235313 301629 469588 84917 364188 449407 392348 436920 26220 198288 162188 468965 274222 92196 463222 408478 231663 467768 382681 38083 412497 160479 280851 268689 101149 25450 62271 9177 38892 268598 273853 250782 191939 89247 40...
output:
499590 1 499999 1 499995 1 499994 1 499989 1 499988 1 499987 1 499983 1 499978 1 499975 1 499972 1 499969 1 499965 1 499964 1 499954 1 499949 1 499947 1 499942 1 499939 1 499932 1 499928 1 499926 1 499925 1 499924 1 499919 1 499918 1 499915 1 499910 1 499909 1 499907 1 4...
result:
ok OK
Test #3:
score: 0
Accepted
time: 178ms
memory: 43352kb
input:
500000 500000 463045 412906 148756 435111 210547 370466 332006 125085 346657 373200 141009 248049 418869 36311 103205 31879 79919 221632 325039 63377 463225 21697 115522 423754 468924 422567 113104 10277 106927 168428 136657 198931 52292 164110 411164 269182 115111 229801 490548 374967 35584 124385 ...
output:
499391 1 499995 1 499994 1 499990 1 499987 1 499985 1 499984 1 499983 1 499980 1 499979 1 499978 1 499977 1 499975 1 499974 1 499973 1 499972 1 499964 1 499962 1 499961 1 499959 1 499956 1 499953 1 499951 1 499947 1 499946 1 499940 1 499936 1 499935 1 499934 1 499933 1 4...
result:
ok OK
Test #4:
score: 0
Accepted
time: 192ms
memory: 43484kb
input:
500000 500000 53335 382346 455173 92221 8244 323792 50176 7825 97274 483122 91479 85438 76999 26861 226585 485061 342260 162826 198446 160509 358060 405334 116619 383398 228241 455075 383689 132273 411544 91882 201903 245543 215635 97032 216514 238391 267192 179008 82221 449619 70697 492859 212515 4...
output:
499543 1 499999 1 499998 1 499997 1 499995 1 499994 1 499993 1 499991 1 499990 1 499987 1 499984 1 499980 1 499976 1 499975 1 499973 1 499972 1 499969 1 499968 1 499960 1 499959 1 499957 1 499954 1 499952 1 499950 1 499948 1 499947 1 499946 1 499941 1 499940 1 499938 1 4...
result:
ok OK
Test #5:
score: 0
Accepted
time: 175ms
memory: 43336kb
input:
500000 500000 429248 25838 130385 474090 301066 98435 160342 325081 58836 93676 332873 451375 243336 362476 378833 389318 68972 375267 209749 483838 405727 431354 477871 331401 30320 382468 228018 369242 53158 111145 464333 346455 436090 431682 22494 69335 128989 418926 392117 10791 347423 40861 389...
output:
499908 1 499998 1 499994 1 499989 1 499987 1 499986 1 499985 1 499983 1 499980 1 499979 1 499976 1 499975 1 499974 1 499973 1 499972 1 499968 1 499965 1 499964 1 499963 1 499958 1 499954 1 499945 1 499944 1 499932 1 499931 1 499927 1 499925 1 499924 1 499921 1 499917 1 4...
result:
ok OK
Test #6:
score: 0
Accepted
time: 178ms
memory: 43332kb
input:
500000 500000 277011 99116 287358 208082 234935 137730 116691 98476 82482 189249 370363 155677 444563 130877 78567 341204 189970 68991 431098 85511 440553 434235 156042 397537 261550 375332 9361 490701 94399 397514 462108 395197 236023 224717 77596 260090 171065 59494 72281 195466 37329 322314 13123...
output:
499959 1 499997 1 499996 1 499992 1 499983 1 499981 1 499980 1 499979 1 499978 1 499968 1 499967 1 499966 1 499964 1 499963 1 499961 1 499959 1 499958 1 499957 1 499956 1 499950 1 499948 1 499945 1 499944 1 499943 1 499939 1 499938 1 499936 1 499933 1 499930 1 499929 1 4...
result:
ok OK
Test #7:
score: 0
Accepted
time: 132ms
memory: 37420kb
input:
389813 410923 255712 339244 274009 248522 347288 199231 235313 301629 84917 364188 26220 198288 162188 274222 92196 231663 382681 38083 160479 280851 268689 101149 25450 62271 9177 38892 268598 273853 250782 191939 89247 384002 197410 212876 258774 238988 55975 128576 220526 321996 203733 68224 2156...
output:
386899 1 389808 1 389806 1 389805 1 389804 1 389803 1 389800 1 389798 1 389796 1 389792 1 389787 1 389777 1 389775 1 389773 1 389769 1 389767 1 389766 1 389760 1 389759 1 389755 1 389753 1 389749 1 389748 1 389746 1 389745 1 389742 1 389741 1 389739 1 389734 1 389729 1 3...
result:
ok OK
Test #8:
score: 0
Accepted
time: 148ms
memory: 40660kb
input:
463046 412907 148756 435111 210547 370466 332006 125085 346657 373200 141009 248049 418869 36311 103205 31879 79919 221632 325039 63377 21697 115522 423754 422567 113104 10277 106927 168428 136657 198931 52292 164110 411164 269182 115111 229801 374967 35584 124385 307573 453747 96444 292667 195578 1...
output:
463024 1 463041 1 463040 1 463039 1 463037 1 463033 1 463028 1 463026 1 463024 1 463022 1 463020 1 463018 1 463016 1 463015 1 463014 1 463011 1 463009 1 463008 1 463007 1 463000 1 462998 1 462996 1 462991 1 462988 1 462987 1 462986 1 462983 1 462982 1 462980 1 462979 1 4...
result:
ok OK
Test #9:
score: 0
Accepted
time: 50ms
memory: 24356kb
input:
53336 382347 26685 8244 50176 7825 31738 24370 25943 19902 11463 26861 29977 26309 14580 31754 1838 29437 30380 12118 51083 31633 1201 18328 26346 5295 48935 19027 31496 19906 41783 5048 47936 16685 5161 34107 15907 28002 332 27672 28930 39563 36429 31696 17876 726 42526 21682 35319 8727 17974 25252...
output:
87 1 52544 1 52131 1 52091 1 51147 1 49821 1 49292 1 49069 1 49039 1 48041 1 41786 1 38700 1 35935 1 32654 1 31150 1 30693 1 30131 1 29555 1 28488 1 28249 1 27910 1 27701 1 25764 1 24488 1 24291 1 23200 1 20997 1 18187 1 12568 1 11778 1 10979 1 7881 1 7456 1 5924 1 4...
result:
ok OK
Test #10:
score: 0
Accepted
time: 57ms
memory: 34636kb
input:
429249 25839 130385 301066 98435 160342 325081 58836 93676 332873 243336 362476 378833 389318 68972 375267 209749 405727 331401 30320 382468 228018 369242 53158 111145 346455 22494 69335 128989 418926 392117 10791 347423 40861 389364 17417 261217 42171 167706 71369 107485 278424 39639 144680 60220 1...
output:
429249 1 429248 1 429247 1 429246 1 429245 1 429244 1 429243 1 429242 1 429241 1 429240 1 429239 1 429238 1 429237 1 429236 1 429235 1 429234 1 429232 1 429231 1 429230 1 429229 1 429228 1 429227 1 429225 1 429224 1 429223 1 429222 1 429221 1 429220 1 429219 1 429218 1 4...
result:
ok OK
Test #11:
score: 0
Accepted
time: 54ms
memory: 28904kb
input:
277012 99117 208082 234935 137730 116691 98476 82482 189249 155677 130877 78567 189970 68991 85511 156042 261550 9361 94399 236023 224717 77596 260090 171065 59494 72281 195466 37329 131235 97595 186133 259682 77924 208661 225412 201669 250472 163723 144340 159695 17876 71198 230537 223132 49533 606...
output:
277012 1 277010 1 277009 1 277008 1 277007 1 277005 1 277004 1 277003 1 277002 1 277001 1 277000 1 276999 1 276998 1 276997 1 276995 1 276994 1 276993 1 276992 1 276991 1 276990 1 276989 1 276988 1 276987 1 276986 1 276985 1 276982 1 276981 1 276980 1 276979 1 276978 1 2...
result:
ok OK