QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#44718#999. 边双连通分量Remakee#AC ✓370ms23844kbC++142.0kb2022-08-21 11:36:022022-08-21 11:36:03

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-21 11:36:03]
  • 评测
  • 测评结果:AC
  • 用时:370ms
  • 内存:23844kb
  • [2022-08-21 11:36:02]
  • 提交

answer

// Skyqwq
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

template <typename T> bool inline chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
template <typename T> bool inline chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }

template <typename T> void inline read(T &x) {
	x = 0; int f = 1; char s = getchar();
	while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); }
	while (s <= '9' && s >= '0') x = x * 10 + s - '0', s = getchar();
	x *= f;
}

const int N = 2e5 + 5, M = 2e5 + 5;

int n, m, A[M], B[M], f[N];

int find(int x) {
	return x == f[x] ? x : f[x] = find(f[x]);
}

void inline merge(int x, int y) {
	x = find(x), y = find(y);
	if (x == y) return ;
	f[x] = y;
}

bool st[M];

int head[N], numE = 1;

struct E{
	int next, v;
} e[M << 1];

void add(int u, int v) {
	e[++numE] = (E) { head[u], v };
	head[u] = numE;
}

int dfn[N], low[N], dfncnt;

void tarjan(int u, int la) {
	dfn[u] = low[u] = ++dfncnt;
	for (int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if ((i ^ 1) == la) continue;
		if (!dfn[v]) {
			tarjan(v, i);
			chkMin(low[u], low[v]);
			if (low[v] > dfn[u]) {
				st[i >> 1] = 1;
			}
		} else chkMin(low[u], dfn[v]);
	}
}

vector<int> b[N];

int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++) f[i] = i;
	for (int i = 1; i <= m; i++) {
		int u, v; read(u), read(v);
		++u, ++v;
		A[i] = u, B[i] = v;
		add(u, v), add(v, u);
	}
	for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan(i, 0);
	for (int i = 1; i <= m; i++)
		if (!st[i]) merge(A[i], B[i]);
	for (int i = 1; i <= n; i++) b[find(i)].pb(i);
	int ct = 0;
	for (int i = 1; i <= n; i++) {
		if (find(i) == i) ct++;
	}
	cout << ct << endl;
	for (int i = 1; i <= n; i++) {
		if (find(i) == i) {
			cout << b[i].size() << " ";
			for (int v: b[i]) cout << v - 1 << " ";
			cout << endl;
		}
	}
	return 0;
}



这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 15468kb

input:

4 5
0 2
0 1
3 0
2 1
2 3

output:

1
4 0 1 2 3 

result:

ok OK

Test #2:

score: 0
Accepted
time: 0ms
memory: 15456kb

input:

13 21
4 5
8 7
12 3
3 10
1 5
10 2
0 0
11 4
2 12
9 1
9 0
7 8
7 6
9 1
8 2
12 10
11 0
8 6
3 2
5 9
4 11

output:

3
6 0 1 4 5 9 11 
4 2 3 10 12 
3 6 7 8 

result:

ok OK

Test #3:

score: 0
Accepted
time: 2ms
memory: 12492kb

input:

2 2
0 1
1 0

output:

1
2 0 1 

result:

ok OK

Test #4:

score: 0
Accepted
time: 370ms
memory: 23692kb

input:

200000 200000
127668 148778
77100 11865
85144 199231
39485 84917
102044 187263
130204 174776
26220 198288
162188 12078
92196 146334
120537 38083
150353 160479
18707 6545
101149 25450
62271 9177
38892 6454
11709 191939
89247 145109
140599 121858
197410 148980
55975 169098
128576 59852
68224 182347
89...

output:

105340
1 0 
1 5 
1 6 
1 7 
1 14 
1 18 
1 20 
1 21 
1 23 
1 24 
1 25 
1 26 
1 28 
1 29 
1 30 
1 31 
1 32 
1 33 
1 35 
1 38 
1 39 
1 40 
1 42 
1 43 
1 44 
1 45 
1 50 
1 53 
1 54 
1 57 
1 62 
1 65 
1 66 
1 68 
1 69 
1 72 
1 73 
1 75 
1 76 
1 81 
1 83 
1 86 
1 88 
1 89 
1 90 
1 91 
1 93 
1 96 
1 103 
1 ...

result:

ok OK

Test #5:

score: 0
Accepted
time: 319ms
memory: 23716kb

input:

200000 200000
150762 148756
172967 108322
69862 125085
84513 111056
141009 156725
36311 103205
31879 79919
62895 63377
21697 115522
161610 160423
113104 10277
106927 168428
136657 198931
52292 164110
149020 7038
115111 112823
35584 124385
45429 191603
96444 30523
195578 149089
160105 58103
139792 27...

output:

104955
1 10 
1 14 
1 15 
1 17 
1 18 
1 19 
1 20 
1 22 
1 24 
1 25 
1 26 
1 28 
1 29 
1 30 
1 32 
1 34 
1 35 
1 36 
1 38 
1 39 
1 41 
1 46 
1 47 
1 49 
1 51 
1 52 
1 54 
1 57 
1 60 
1 61 
1 62 
1 64 
1 69 
1 78 
1 81 
1 82 
1 85 
1 86 
1 88 
1 92 
1 93 
1 94 
1 95 
1 96 
1 97 
1 98 
1 99 
1 101 
1 10...

result:

ok OK

Test #6:

score: 0
Accepted
time: 353ms
memory: 23844kb

input:

200000 200000
53335 120202
193029 92221
8244 61648
50176 7825
97274 91479
85438 76999
26861 80116
162826 198446
160509 95916
143190 116619
121254 192931
121545 132273
149400 91882
97032 5048
179008 82221
187475 70697
159074 65868
158744 94466
120006 170635
36429 162768
61114 17876
131798 188508
1080...

output:

105649
1 2 
1 3 
1 4 
1 5 
1 6 
1 9 
1 11 
1 12 
1 13 
1 15 
1 18 
1 19 
1 21 
1 23 
1 24 
1 26 
1 27 
1 28 
1 29 
1 30 
1 31 
1 32 
1 35 
1 36 
1 37 
1 40 
1 41 
1 42 
1 43 
1 46 
1 47 
1 48 
1 49 
1 50 
1 52 
1 53 
1 54 
1 58 
1 61 
1 64 
1 67 
1 68 
1 69 
1 70 
1 71 
1 73 
1 74 
1 75 
1 77 
1 79 ...

result:

ok OK

Test #7:

score: 0
Accepted
time: 239ms
memory: 21060kb

input:

127669 148779
124640 77100
11865 117450
85144 68159
104241 39485
76372 84917
102044 56191
43704 26220
67216 31116
75749 123504
12078 92196
70006 15262
100591 74552
120537 38083
19281 29407
18707 6545
101149 25450
62271 9177
38892 6454
11709 119710
60867 89247
14037 9527
121858 66338
112298 81804
795...

output:

51131
1 1 
1 2 
1 3 
1 4 
1 7 
1 14 
1 16 
1 20 
1 24 
1 25 
1 27 
1 28 
1 29 
1 32 
1 33 
1 34 
1 38 
1 40 
1 42 
1 43 
1 53 
1 54 
1 55 
1 57 
1 59 
1 60 
1 68 
1 76 
1 81 
1 83 
1 85 
1 86 
1 88 
1 89 
1 99 
1 103 
1 104 
1 107 
1 108 
1 115 
1 116 
1 117 
1 118 
1 121 
1 124 
1 126 
1 127 
1 134...

result:

ok OK

Test #8:

score: 0
Accepted
time: 156ms
memory: 21476kb

input:

150763 148757
108322 69862
125085 84513
111056 141009
36311 103205
31879 79919
62895 63377
21697 115522
113104 10277
106927 136657
52292 149020
7038 115111
112823 35584
124385 45429
96444 30523
149089 58103
139792 27250
15883 109949
69372 132387
141930 113408
65522 128254
138198 141969
42522 92075
1...

output:

81019
1 2 
1 7 
1 14 
1 17 
1 18 
1 19 
1 20 
1 22 
1 24 
1 25 
1 26 
1 28 
1 29 
1 30 
1 32 
1 34 
1 35 
1 36 
1 38 
1 39 
1 41 
1 47 
1 49 
1 51 
1 52 
1 53 
1 54 
1 57 
1 60 
1 62 
1 64 
1 66 
1 68 
1 69 
1 70 
1 73 
1 78 
1 80 
1 81 
1 82 
1 85 
1 86 
1 90 
1 93 
1 94 
1 95 
1 96 
1 97 
1 98 
1 ...

result:

ok OK

Test #9:

score: 0
Accepted
time: 40ms
memory: 18024kb

input:

53336 120203
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:

3392
1 2 
1 7 
1 13 
1 20 
1 46 
1 61 
1 87 
1 99 
1 128 
1 132 
1 133 
1 143 
1 196 
1 200 
1 236 
1 239 
1 272 
1 275 
1 283 
1 352 
1 359 
1 367 
1 395 
1 406 
1 411 
1 413 
1 415 
1 451 
1 473 
1 479 
1 484 
1 490 
1 495 
1 516 
1 534 
1 547 
1 576 
1 587 
1 593 
1 600 
1 614 
1 622 
1 641 
1 65...

result:

ok OK

Test #10:

score: 0
Accepted
time: 12ms
memory: 15788kb

input:

17707 71661
1354 3272
13699 17294
16733 9246
14993 5758
7252 2983
3813 6121
10450 14069
8088 11201
857 4420
12788 2032
11938 1465
10322 15171
14688 1857
2309 2742
2013 13200
14142 16319
10541 1922
10368 1516
7994 9092
3327 5166
13484 2876
15472 13522
15622 13479
3361 15314
15464 14974
17637 7535
435...

output:

75
1 182 
16444 0 1 2 3 4 5 6 7 8 9 10 11 12 15 16 18 19 20 21 22 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47 48 49 50 51 52 54 55 56 57 58 59 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 97 98 99 100 101 103 104 105 1...

result:

ok OK

Test #11:

score: 0
Accepted
time: 2ms
memory: 16052kb

input:

4294 17517
1175 3250
314 389
4272 3633
2938 1831
1307 2818
3321 347
1205 1428
2354 1478
1003 3898
1587 3443
1122 1512
2512 3995
348 3280
2064 1022
1834 2958
4281 1863
689 3613
2115 3708
1645 1488
1601 4181
916 4276
128 2626
4147 2868
87 1411
1802 1451
1254 2010
2936 3120
1065 277
1121 3284
3655 2849...

output:

29
1 280 
1 538 
1 651 
1 1058 
1 1062 
3031 0 2 3 4 5 7 9 10 11 13 15 16 18 19 20 21 25 26 27 28 29 31 33 34 35 36 37 38 39 40 41 43 46 47 48 50 51 52 53 55 56 57 59 60 61 62 64 66 67 68 69 70 71 72 73 74 75 77 78 80 82 83 84 85 87 91 92 93 95 98 99 100 101 104 105 107 108 110 111 113 114 116 117 1...

result:

ok OK

Test #12:

score: 0
Accepted
time: 4ms
memory: 16412kb

input:

26686 105813
14774 5315
22701 21346
1398 13888
18566 18745
22298 6181
21347 10653
16500 23768
2329 5818
17512 16769
25519 338
12580 3064
19467 21665
3978 13202
23556 25178
195 9695
1472 13111
22925 24074
3026 13281
17666 14469
22007 18680
4159 13152
20431 23814
6671 10788
24433 13211
9794 12608
3264...

output:

137
1 188 
1 345 
1 371 
487 32 54 122 210 216 268 327 420 456 496 509 553 594 671 763 768 898 957 973 1113 1177 1279 1372 1460 1519 1522 1552 1579 1589 1657 1668 1669 1692 1827 1907 1934 1954 2180 2185 2230 2287 2292 2332 2337 2377 2405 2410 2498 2635 2713 2731 2814 2848 2852 3015 3024 3082 3256 32...

result:

ok OK

Test #13:

score: 0
Accepted
time: 27ms
memory: 16808kb

input:

36033 148595
33366 22486
14414 23855
2694 30361
16352 31902
27993 2048
4707 31743
30610 12884
23278 27069
10529 20914
2030 30015
24554 15673
10184 29423
17825 20383
34077 1181
25518 26129
6355 8810
2857 21736
25108 34280
14992 24299
32649 20227
34529 10407
23194 29913
10451 319
34666 8904
30811 3003...

output:

150
1 206 
1 236 
7961 0 4 5 9 20 21 23 30 40 43 45 46 48 51 52 55 58 62 68 77 78 80 87 91 96 98 99 118 127 128 131 137 140 148 149 151 153 159 165 167 169 172 174 192 202 211 212 214 223 224 225 227 232 238 244 245 248 250 251 254 257 261 262 263 269 281 293 299 319 320 324 325 326 330 333 334 336 ...

result:

ok OK

Test #14:

score: 0
Accepted
time: 9ms
memory: 16408kb

input:

14868 57739
5724 2103
9214 3074
2269 531
3811 13162
5199 12632
6337 12078
12592 4977
3553 6975
5063 6622
1221 13056
4252 3705
7547 7879
1702 3685
4058 2503
7540 9423
4280 12228
574 6265
11876 2711
4805 7605
1468 4802
6921 1954
6350 2733
4429 5862
13549 14543
13809 5357
1509 11478
87 2676
6299 7060
1...

output:

80
1 84 
1 150 
1 646 
1 809 
1 1013 
1 1032 
1 1040 
1 1333 
1 1860 
1 2033 
1 2470 
1 2698 
1 2754 
1 2864 
1 3277 
1 3439 
5372 0 4 9 12 16 17 18 19 20 21 22 24 26 33 35 36 39 41 42 44 47 50 54 56 62 65 66 68 72 73 75 76 81 82 86 87 91 95 96 97 100 101 103 108 111 115 117 119 124 125 127 132 135 ...

result:

ok OK

Test #15:

score: 0
Accepted
time: 6ms
memory: 12864kb

input:

53 43
32 44
25 10
24 49
20 28
28 44
16 12
37 48
46 36
30 47
25 3
17 31
19 17
29 42
25 44
30 3
31 21
2 34
42 12
22 50
12 52
39 10
0 46
29 1
12 21
3 0
11 31
42 25
4 51
26 36
19 48
39 26
5 21
7 41
29 34
38 47
29 8
26 17
42 46
36 20
39 30
13 27
28 31
27 24

output:

37
1 1 
1 2 
1 4 
1 5 
1 6 
1 7 
1 8 
1 9 
1 11 
1 13 
1 14 
1 15 
1 16 
1 18 
1 19 
1 22 
1 23 
1 24 
1 27 
1 29 
1 32 
1 33 
1 34 
1 35 
17 0 3 10 12 17 20 21 25 26 28 30 31 36 39 42 44 46 
1 37 
1 38 
1 40 
1 41 
1 43 
1 45 
1 47 
1 48 
1 49 
1 50 
1 51 
1 52 

result:

ok OK

Test #16:

score: 0
Accepted
time: 0ms
memory: 15284kb

input:

70 21
39 34
29 33
38 53
37 7
47 64
47 17
65 66
60 39
37 47
19 68
14 28
39 41
52 55
0 60
59 16
11 40
11 33
35 26
0 11
24 17
26 43

output:

70
1 0 
1 1 
1 2 
1 3 
1 4 
1 5 
1 6 
1 7 
1 8 
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 37 
1 38 
1 39 
1 40 
1 41 
1 42 
1 43 
1 44 
1 45 
1 46 
1 47 
1 48 
1 49 
1 50 
1...

result:

ok OK

Test #17:

score: 0
Accepted
time: 1ms
memory: 15788kb

input:

88 139
5 61
52 80
0 17
50 87
62 71
25 69
10 46
44 86
11 38
17 35
73 49
24 47
39 83
8 66
55 56
64 45
83 41
59 35
76 24
2 70
11 77
80 58
84 86
30 50
23 54
36 74
12 10
62 75
33 34
43 28
77 29
10 46
77 33
26 48
32 38
52 79
15 30
25 57
86 0
46 75
81 60
35 83
66 87
25 86
19 85
9 38
15 64
59 82
0 53
40 66
...

output:

16
1 12 
1 13 
1 16 
1 18 
1 31 
1 34 
1 42 
1 45 
1 47 
1 51 
1 53 
1 54 
1 68 
73 0 1 2 3 4 5 6 7 8 9 10 11 14 15 17 19 20 21 22 23 24 25 26 27 28 29 30 32 33 35 36 37 38 39 40 41 43 44 46 48 49 50 52 55 56 57 58 59 60 61 62 63 64 65 66 67 69 70 71 72 73 75 76 77 78 79 80 81 83 84 85 86 87 
1 74 
...

result:

ok OK

Test #18:

score: 0
Accepted
time: 4ms
memory: 14020kb

input:

53 185
48 40
23 7
45 7
6 42
13 6
45 1
18 28
47 14
11 15
27 9
50 44
23 47
20 27
18 19
2 19
18 49
32 49
9 12
11 0
32 49
22 14
8 48
41 28
30 43
4 21
7 22
28 30
17 11
19 30
44 7
46 8
50 45
35 48
29 47
4 26
16 39
37 25
38 12
19 52
28 41
23 31
33 34
6 15
44 24
0 6
26 22
49 43
4 31
20 38
43 39
41 39
51 40
...

output:

3
20 0 3 6 8 9 10 11 12 13 15 17 20 27 35 38 40 42 46 48 51 
16 1 4 5 7 14 21 22 23 24 26 29 31 44 45 47 50 
17 2 16 18 19 25 28 30 32 33 34 36 37 39 41 43 49 52 

result:

ok OK

Test #19:

score: 0
Accepted
time: 5ms
memory: 12804kb

input:

70 252
63 36
64 48
26 34
43 37
30 53
67 64
26 19
25 54
28 44
52 60
4 22
43 48
14 48
12 50
37 23
28 40
48 54
60 23
43 46
7 5
29 39
5 13
57 60
1 23
33 8
59 39
3 29
5 8
34 11
44 40
39 19
40 17
42 48
39 19
49 46
0 48
46 45
57 67
43 60
56 59
32 42
6 54
56 69
23 43
38 65
66 24
0 64
16 10
23 1
4 16
37 49
5...

output:

1
70 0 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 

result:

ok OK

Test #20:

score: 0
Accepted
time: 5ms
memory: 15648kb

input:

88 390
74 40
14 37
44 66
7 49
12 4
39 48
56 76
46 40
80 30
5 39
52 0
40 79
0 11
34 41
43 80
54 62
61 41
54 37
31 81
59 66
23 59
47 84
16 85
68 29
31 63
4 55
27 5
26 68
14 84
16 34
82 16
62 54
46 15
65 63
58 83
5 36
67 19
65 42
35 25
82 73
55 59
28 36
22 38
46 79
61 34
51 40
69 42
36 5
26 38
86 14
22...

output:

3
6 9 20 33 56 76 77 
6 5 27 36 39 48 60 
76 0 1 2 3 4 6 7 8 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 28 29 30 31 32 34 35 37 38 40 41 42 43 44 45 46 47 49 50 51 52 53 54 55 57 58 59 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 78 79 80 81 82 83 84 85 86 87 

result:

ok OK