QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#92685 | #906. 强连通分量 | wzh2021# | AC ✓ | 623ms | 121052kb | C++14 | 1.5kb | 2023-03-30 20:52:39 | 2023-03-30 20:52:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pr = pair <int, int>;
#define _1 first
#define _2 second
const int N = 1000010;
bool vis[N];
int deg[N], que[N];
int n, m, tot, top, cnt;
int col[N], dfn[N], low[N], stk[N];
vector <int> vec[N], scc[N], vec2[N];
void tarjan(int x) {
dfn[x] = low[x] = ++tot;
stk[++top] = x;
vis[x] = 1;
for (int y : vec[x])
if (!dfn[y]) {
tarjan(y);
low[x] = min(low[x], low[y]);
} else if (vis[y])
low[x] = min(low[x], dfn[y]);
if (dfn[x] == low[x]) {
++cnt;
for (; stk[top] ^ x; --top) {
col[stk[top]] = cnt;
vis[stk[top]] = 0;
scc[cnt].emplace_back(stk[top]);
}
col[x] = cnt;
vis[x] = 0;
scc[cnt].emplace_back(x);
--top;
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; ++i) {
int u, v;
scanf("%d%d", &u, &v);
++u;
++v;
vec[u].emplace_back(v);
}
for (int i = 1; i <= n; ++i)
if (!dfn[i])
tarjan(i);
printf("%d\n", cnt);
for (int i = 1; i <= n; ++i)
for (int j : vec[i])
if (col[i] ^ col[j]) {
vec2[col[i]].emplace_back(col[j]);
++deg[col[j]];
}
tot = 0;
for (int i = 1; i <= cnt; ++i)
if (!deg[i])
que[++tot] = i;
for (int i = 1; i <= cnt; ++i) {
int x = que[i];
for (int y : vec2[x])
if (!--deg[y])
que[++tot] = y;
}
for (int i = 1; i <= cnt; ++i) {
printf("%llu ", scc[que[i]].size());
for (int j : scc[que[i]])
printf("%d ", j - 1);
puts("");
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 22ms
memory: 75580kb
input:
6 7 1 4 5 2 3 0 5 5 4 1 0 3 4 2
output:
4 2 3 0 2 4 1 1 5 1 2
result:
ok OK
Test #2:
score: 0
Accepted
time: 588ms
memory: 120172kb
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 3 1 4 1 5 1 6 1 7 1 10 1 13 1 14 1 17 1 19 1 20 1 21 1 24 1 25 1 26 1 27 1 31 1 32 1 34 1 37 1 39 1 42 1 43 1 46 1 47 1 59 1 60 1 67 1 68 1 76 1 80 1 85 1 86 1 88 1 89 1 94 1 107 1 111 1 113 1 114 1 119 1 120 1 121 1 123 1 129 1 130 1 132 1 133...
result:
ok OK
Test #3:
score: 0
Accepted
time: 623ms
memory: 121052kb
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 1 1 2 1 6 1 12 1 13 1 18 1 19 1 20 1 25 1 26 1 28 1 32 1 36 1 38 1 41 1 47 1 48 1 49 1 51 1 52 1 57 1 60 1 68 1 70 1 71 1 72 1 73 1 74 1 77 1 78 1 79 1 81 1 84 1 86 1 95 1 96 1 98 1 99 1 101 1 102 1 106 1 107 1 110 1 112 1 113 1 121 1 124 1 134...
result:
ok OK
Test #4:
score: 0
Accepted
time: 599ms
memory: 120316kb
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 1 1 2 1 3 1 6 1 7 1 8 1 12 1 13 1 16 1 18 1 19 1 21 1 23 1 26 1 30 1 34 1 35 1 37 1 40 1 42 1 43 1 45 1 56 1 61 1 66 1 67 1 68 1 70 1 74 1 75 1 81 1 82 1 88 1 89 1 96 1 103 1 104 1 105 1 109 1 110 1 111 1 124 1 125 1 131 1 132 1 133 1 135 1 136...
result:
ok OK
Test #5:
score: 0
Accepted
time: 550ms
memory: 120852kb
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 1 1 5 1 9 1 10 1 12 1 14 1 15 1 17 1 19 1 21 1 24 1 29 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 42 1 43 1 49 1 50 1 54 1 56 1 61 1 63 1 64 1 68 1 70 1 71 1 73 1 78 1 82 1 84 1 86 1 87 1 88 1 91 1 92 1 93 1 94 1 96 1 97 1 101 1 105 1 108 1 110 1 11...
result:
ok OK
Test #6:
score: 0
Accepted
time: 580ms
memory: 119840kb
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 0 1 1 1 3 1 9 1 11 1 13 1 15 1 16 1 17 1 18 1 19 1 22 1 28 1 29 1 31 1 34 1 35 1 36 1 38 1 39 1 40 1 45 1 46 1 50 1 57 1 58 1 59 1 60 1 61 1 64 1 68 1 69 1 70 1 71 1 75 1 76 1 79 1 83 1 85 1 90 1 93 1 95 1 98 1 101 1 103 1 105 1 106 1 110 1 11...
result:
ok OK
Test #7:
score: 0
Accepted
time: 528ms
memory: 113204kb
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 0 1 2 1 5 1 7 1 12 1 14 1 19 1 20 1 21 1 24 1 25 1 26 1 28 1 31 1 32 1 33 1 34 1 37 1 38 1 39 1 42 1 47 1 48 1 49 1 51 1 55 1 59 1 71 1 82 1 85 1 88 1 89 1 90 1 96 1 98 1 105 1 106 1 107 1 111 1 113 1 114 1 115 1 120 1 128 1 129 1 131 1 133 1 1...
result:
ok OK
Test #8:
score: 0
Accepted
time: 564ms
memory: 116456kb
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 2 1 6 1 11 1 12 1 13 1 17 1 18 1 24 1 25 1 26 1 29 1 32 1 38 1 41 1 43 1 44 1 47 1 49 1 51 1 52 1 55 1 57 1 60 1 63 1 68 1 70 1 71 1 75 1 76 1 78 1 81 1 82 1 84 1 85 1 86 1 89 1 92 1 93 1 94 1 96 1 99 1 101 1 106 1 107 1 110 1 113 1 114 1 116 ...
result:
ok OK
Test #9:
score: 0
Accepted
time: 134ms
memory: 82736kb
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 1694 1 2827 1 4368 1 4989 1 5924 1 7456 1 7881 1 10979 1 11778 1 12568 1 18187 1 20997 1 23200 1 24291 1 24488 1 25764 1 27701 1 27910 1 28249 1 28488 1 29555 1 30131 1 30693 1 31150 1 32654 1 35935 1 38700 1 41786 1 48041 1 49039 1 49069 1 49292 1 49821 1 51147...
result:
ok OK
Test #10:
score: 0
Accepted
time: 109ms
memory: 99160kb
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 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 50 1 52 1 53 1 ...
result:
ok OK
Test #11:
score: 0
Accepted
time: 154ms
memory: 93688kb
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 0 1 1 1 2 1 3 1 4 1 5 1 8 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 21 1 22 1 23 1 24 1 25 1 26 1 29 1 31 1 32 1 33 1 34 1 35 1 37 1 38 1 39 1 40 1 41 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 52 1 53 1 54 1 55 1 57 1 58 1 60 1 61 1 62 1 63 ...
result:
ok OK