QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#341102#999. 边双连通分量iorit#AC ✓64ms24564kbC++141.5kb2024-02-29 15:42:322024-02-29 15:42:34

Judging History

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

  • [2024-02-29 15:42:34]
  • 评测
  • 测评结果:AC
  • 用时:64ms
  • 内存:24564kb
  • [2024-02-29 15:42:32]
  • 提交

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 = 2e5 + 10;
const int inf = ~0u >> 2;
int n,m;
struct edge
{
	int v,w,nxt;
}e[N << 1];
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];
bool vis[N << 1];
int tot,st[N],top;
vector<int> vc[N];
void dfs(int u)
{
	// cout << u << endl;
	dfn[u] = low[u] = ++dfn_t;
	st[++top] = u;
	for(int i = hd[u];i;i = e[i].nxt)
	{
		if(vis[i] )
			continue;
		int v = e[i].v;
		if(dfn[v] )
			low[u] = min(low[u] , dfn[v] );
		else
		{
			vis[i] = vis[i ^ 1] = 1;
			dfs(v);
			low[u] = min(low[u] , low[v] );
			if( low[v] == dfn[v] )
			{
				++tot;
				int w;
				do
				{
					w = st[top--];
					vc[tot].push_back(w);
				}while(w != v);
			}
		}
	}
	// cout << u << " low= " << low[u] << " dfn= " << dfn[u] << endl;
}
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),add(v , u);
	}
	for(int i = 1;i <= n;i++)
	{
		if( !dfn[i] )
		{
			dfs(i);
			if(top)
			{
				++tot;
				for(int i = 1;i <= top;i++)
					vc[tot].push_back( st[i] );
				top = 0;
			}
		}
	}
	cout << tot << endl;
	for(int i = 1;i <= tot;i++)
	{
		printf("%d " , vc[i].size() );
		for(int x : vc[i] )
			printf("%d " , x - 1);
		endline;
	}
	return 0;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 8620kb

input:

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

output:

1
4 0 3 2 1 

result:

ok OK

Test #2:

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

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 11 4 5 9 1 
3 7 6 8 
4 2 3 10 12 

result:

ok OK

Test #3:

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

input:

2 2
0 1
1 0

output:

1
2 0 1 

result:

ok OK

Test #4:

score: 0
Accepted
time: 54ms
memory: 24564kb

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 187755 
1 125231 
1 64929 
1 82097 
1 51090 
1 136464 
1 116597 
1 129798 
1 161502 
1 94362 
1 125004 
1 177202 
1 139581 
1 165793 
1 33838 
1 14613 
1 96082 
1 185256 
1 138659 
1 10704 
1 2426 
1 108507 
1 15298 
1 174772 
1 54060 
1 52863 
1 112474 
1 75320 
1 125800 
1 90149 
1 164599...

result:

ok OK

Test #5:

score: 0
Accepted
time: 64ms
memory: 24508kb

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 186441 
1 189433 
1 8872 
1 173494 
1 78841 
1 33396 
1 55811 
1 18809 
1 165080 
1 80200 
1 189683 
1 61324 
1 94035 
1 85022 
1 71511 
1 96515 
1 41645 
1 122857 
1 51706 
1 82414 
1 30677 
1 188052 
1 67162 
1 3303 
1 5596 
1 84880 
1 197951 
1 154083 
1 137778 
1 84907 
1 10220 
1 76847...

result:

ok OK

Test #6:

score: 0
Accepted
time: 59ms
memory: 24464kb

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 162568 
1 134603 
1 58322 
1 191921 
1 88887 
1 59095 
1 148222 
1 38293 
1 184167 
1 138084 
1 78359 
1 28181 
1 68744 
1 129730 
1 54256 
1 4839 
1 148928 
1 128678 
1 172667 
1 187248 
1 173992 
1 105401 
1 171483 
1 155850 
1 58776 
1 67992 
1 114500 
1 46721 
1 184113 
1 127341 
1 2108...

result:

ok OK

Test #7:

score: 0
Accepted
time: 39ms
memory: 19852kb

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 118424 
1 75272 
1 20503 
1 72713 
1 60458 
1 81378 
1 51988 
1 26994 
1 52687 
1 20162 
1 40217 
1 101545 
1 44914 
1 61634 
1 67122 
1 26911 
1 12601 
1 90310 
1 17957 
1 126232 
1 17223 
1 68434 
1 88874 
1 98799 
1 107148 
1 100458 
1 33203 
1 99283 
1 44560 
1 74476 
1 98969 
1 41088 
1...

result:

ok OK

Test #8:

score: 0
Accepted
time: 43ms
memory: 20440kb

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 101125 
1 78319 
1 143178 
1 121982 
1 72301 
1 77173 
1 10609 
1 16581 
1 59616 
1 117417 
1 1671 
1 51166 
1 8706 
1 25742 
1 9880 
1 127087 
1 127950 
1 91373 
1 134208 
1 66846 
1 110346 
1 146335 
1 116234 
1 61049 
1 24700 
1 32180 
1 45923 
1 8056 
1 71425 
1 29701 
1 125750 
1 126358...

result:

ok OK

Test #9:

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

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 27581 
1 25082 
1 47475 
1 44967 
1 40512 
1 42891 
1 17694 
1 40771 
1 33725 
1 20298 
1 10999 
1 3492 
1 6400 
1 32608 
1 4466 
1 17115 
1 15738 
1 10373 
1 34595 
1 14623 
1 27715 
1 8271 
1 20720 
1 24517 
1 49996 
1 26364 
1 10638 
1 20669 
1 50111 
1 24008 
1 33805 
1 50227 
1 13460 
1 ...

result:

ok OK

Test #10:

score: 0
Accepted
time: 11ms
memory: 11284kb

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 6755 
1 15390 
1 6226 
1 1593 
1 15854 
1 7977 
1 8990 
1 5846 
1 14567 
1 12473 
1 5505 
1 5504 
1 14057 
1 17102 
1 13333 
1 13541 
1 9878 
1 6026 
1190 14184 16576 5380 10029 4324 10897 13494 4002 15668 8594 10917 6971 7251 10895 16372 3683 8035 7286 5906 6137 7446 17330 12447 8043 8783 1446...

result:

ok OK

Test #11:

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

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 2756 
432 2354 2020 3803 3588 1780 186 800 2697 2503 2331 749 3934 3708 4289 2536 4198 990 1281 724 1851 2778 923 1631 2275 590 1434 3134 2645 1755 3874 3964 3362 198 2684 112 1415 874 115 3140 2349 3643 2958 2865 693 3059 1515 599 1745 3293 855 3469 918 2699 1670 4054 4070 488 1815 3126 2858 4...

result:

ok OK

Test #12:

score: 0
Accepted
time: 22ms
memory: 12288kb

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 23394 
1 12475 
1 2118 
1 22100 
1 10070 
1 15273 
1 26505 
1 20785 
1 6022 
1 651 
1 10917 
1 371 
1 8727 
1 18510 
1 12486 
1 8793 
1 5458 
1 15559 
1 22179 
1 26437 
1 8682 
1 17160 
1 5841 
1 13843 
1 18834 
1 23868 
1 6744 
1 10300 
1 1219 
1 16355 
1 1538 
1 8709 
1 24928 
1 24377 
1 249...

result:

ok OK

Test #13:

score: 0
Accepted
time: 26ms
memory: 13260kb

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 2952 
1 909 
1 35383 
1 10070 
1 15933 
1 206 
1 7652 
1 32601 
1 26526 
1 24825 
1 2237 
1 28026 
1 2228 
1 28914 
1 29816 
1 10445 
1 26444 
1 7683 
1 20693 
1 16543 
1 31025 
1 14407 
7961 0 8630 4929 27050 9220 14736 4117 4908 10947 6498 27469 13587 36031 29899 29576 11510 2957 12223 22436...

result:

ok OK

Test #14:

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

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 13153 
1 10106 
1 8376 
1 2754 
1 12664 
1 13378 
1 1333 
1 4879 
1 11854 
1 12071 
1 4095 
1 5231 
1 5553 
1 7206 
1 11682 
1 1040 
1 9966 
1 9596 
1 1032 
1 14047 
1 5441 
1 9447 
1 3439 
1 5188 
1 9802 
1 5162 
1 13959 
1 2698 
1 150 
1 1860 
1 10345 
1 9764 
1 10402 
1 84 
1 10801 
1 10861 ...

result:

ok OK

Test #15:

score: 0
Accepted
time: 3ms
memory: 8584kb

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

result:

ok OK

Test #16:

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

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 29 
1 33 
1 40 
1 11 
1 41 
1 34 
1 39 
1 60 
1 0 
1 1 
1 2 
1 3 
1 4 
1 5 
1 6 
1 24 
1 17 
1 64 
1 47 
1 37 
1 7 
1 8 
1 9 
1 10 
1 12 
1 13 
1 28 
1 14 
1 15 
1 59 
1 16 
1 18 
1 68 
1 19 
1 20 
1 21 
1 22 
1 23 
1 25 
1 43 
1 35 
1 26 
1 27 
1 30 
1 31 
1 32 
1 36 
1 53 
1 38 
1 42 
1 44 
1...

result:

ok OK

Test #17:

score: 0
Accepted
time: 3ms
memory: 8604kb

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

result:

ok OK

Test #18:

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

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

result:

ok OK

Test #19:

score: 0
Accepted
time: 3ms
memory: 8516kb

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 52 25 32 51 54 14 43 45 49 48 67 22 65 31 44 17 38 55 61 8 53 41 56 62 2 12 33 5 39 50 29 59 11 7 35 30 18 21 26 68 9 13 69 19 34 3 6 60 64 15 42 23 57 1 37 46 66 47 24 10 36 63 16 4 28 40 27 58 20 

result:

ok OK

Test #20:

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

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

result:

ok OK