QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#421440#961. Smol Vertex CovercqbzlyTL 1534ms6680kbC++203.7kb2024-05-25 18:47:282024-05-25 18:47:30

Judging History

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

  • [2024-05-25 18:47:30]
  • 评测
  • 测评结果:TL
  • 用时:1534ms
  • 内存:6680kb
  • [2024-05-25 18:47:28]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
using namespace std;
const int N=505;
int T,n,m,cnt,used[N],to[N],bl[N],fa[N],sb;
int low[N],dfn[N],num,fk[N],vs[N];
stack<int>stk;
vector<int>G[N];
vector<int>G0[N]; 
pair<int,int>a[N*N];
pair<int,int>p[N];
mt19937 gen(time(0));
bool dfs(int u){
	used[u]=1;
	shuffle(G[u].begin(),G[u].end(),gen);
	for(auto v:G[u]){
		if(used[v])continue;
		used[v]=1;
		int x=to[v];
		to[u]=v,to[v]=u,to[x]=0;
		if(!x||dfs(x))return 1;
		to[v]=x,to[x]=v,to[u]=0;
	}
	return 0;
}
void init(){
	for(int i=1;i<=2*cnt;i++)fa[i]=i,dfn[i]=low[i]=fk[i]=vs[i]=0,G0[i].clear();num=sb=0;
}
void add(int x,int y){
	G0[x].pb(y);
}
void work(int u,int v){
	if(!bl[u]){
		if(v==p[bl[v]].fi)add(bl[v]+cnt,bl[v]);
		else add(bl[v],bl[v]+cnt);
	}
	else if(!bl[v]){
		if(u==p[bl[u]].fi)add(bl[u]+cnt,bl[u]);
		else add(bl[u],bl[u]+cnt);
	}
	else{
		int x=(u==p[bl[u]].se),y=(v==p[bl[v]].se);
		add(bl[u]+(1-x)*cnt,bl[v]+y*cnt);
		add(bl[v]+(1-y)*cnt,bl[u]+x*cnt); 
	}
}
void tarjan(int u){
	low[u]=dfn[u]=++num,stk.push(u),vs[u]=1;
	for(auto v:G0[u]){
		if(!dfn[v]){
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(vs[v]){
			low[u]=min(low[u],dfn[v]);
		}
	}
	if(low[u]==dfn[u]){
		int tmp=0;sb++;
		do{
			tmp=stk.top(),stk.pop();
			fk[tmp]=sb,vs[tmp]=0;
		}while(tmp!=u);
	}
}
int main(){
	//freopen("data.in","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
//	cin>>T;
//	while(T--){
		cin>>n>>m;for(int i=1;i<=n;i++)G[i].clear(),bl[i]=to[i]=0;
		for(int i=1;i<=m;i++){
			int u,v;cin>>u>>v;
			G[u].pb(v),G[v].pb(u);
			if(!to[u]&&!to[v])to[u]=v,to[v]=u;
			//cout<<"edge:"<<u<<" "<<v<<"\n";
			a[i]={u,v};
		}
		for(int k=1;k<=1000;k++){
			for(int i=1;i<=n;i++){
				if(!to[i]){
					for(int j=1;j<=n;j++)used[j]=0;
					dfs(i);
				}
			}
		}
		cnt=0;
		for(int i=1;i<=n;i++){
			if(to[i]&&i<to[i]){
				p[++cnt]={i,to[i]};
				bl[i]=bl[to[i]]=cnt;
			}
		}
//		cout<<cnt<<"\n";
//		 for(int i=1;i<=cnt;i++){
//		 	cout<<p[i].fi<<" "<<p[i].se<<"\n";
//		 }
		init();
		for(int i=1;i<=m;i++){
			int u=a[i].fi,v=a[i].se;
			if(bl[u]==bl[v])continue;
			work(u,v);
		}
		for(int i=1;i<=cnt*2;i++)if(!dfn[i])tarjan(i);
		bool ok=1;
		for(int i=1;i<=cnt;i++)if(fk[i]==fk[i+cnt])ok=0;
		if(ok){
			cout<<cnt<<"\n";
			for(int i=1;i<=cnt;i++){
				if(fk[i]<fk[i+cnt])cout<<p[i].fi<<" ";
				else cout<<p[i].se<<" ";
			}
			cout<<"\n";
		}
		else{
			bool flg=0;
			for(int i=1;i<=n;i++){
				init();
				if(to[i]){
					for(int j=1;j<=m;j++){
						int u=a[j].fi,v=a[j].se;
						if(bl[u]==i||bl[v]==i||bl[u]==bl[v])continue;
						work(u,v);
					}
					for(int j=1;j<=cnt*2;j++)if(!dfn[j])tarjan(j);
					bool ok=1;
					for(int j=1;j<=cnt;j++)if(fk[j]==fk[j+cnt])ok=0;
					if(ok){
						flg=1;
						cout<<cnt+1<<"\n";
						for(int j=1;j<=cnt;j++){
							if(j==i)cout<<p[j].fi<<" "<<p[j].se<<" ";
							else if(fk[j]<fk[j+cnt])cout<<p[j].fi<<" ";
							else cout<<p[j].se<<" ";
						}
						cout<<"\n";
						break;
					}
				}
				else{
					for(int j=1;j<=m;j++){
						int u=a[j].fi,v=a[j].se;
						if(u==i||v==i||bl[u]==bl[v])continue;
						work(u,v);
					}
					for(int j=1;j<=cnt*2;j++)if(!dfn[j])tarjan(j);
					bool ok=1;
					for(int j=1;j<=cnt;j++)if(fk[j]==fk[j+cnt])ok=0;
					if(ok){
						flg=1;
						cout<<cnt+1<<"\n";
						cout<<i<<" ";
						for(int j=1;j<=cnt;j++){
							if(fk[j]<fk[j+cnt])cout<<p[j].fi<<" ";
							else cout<<p[j].se<<" ";
						}
						cout<<"\n";
						break;
					}
				}
			}
			if(!flg)cout<<"not smol"<<"\n";
		}
//	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3724kb

input:

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

output:

3
1 2 4 

result:

ok vertex cover of size 3

Test #2:

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

input:

5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

output:

not smol

result:

ok not smol

Test #3:

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

input:

3 0

output:

0


result:

ok vertex cover of size 0

Test #4:

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

input:

10 10
2 5
3 8
3 10
6 9
1 4
2 6
2 3
4 6
7 10
4 7

output:

5
1 2 3 6 7 

result:

ok vertex cover of size 5

Test #5:

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

input:

10 20
1 9
3 6
3 7
8 9
3 8
1 4
5 10
7 10
4 6
7 9
9 10
2 7
1 6
5 8
2 9
1 7
5 7
3 10
2 6
4 10

output:

6
1 9 6 8 10 7 

result:

ok vertex cover of size 6

Test #6:

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

input:

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

output:

not smol

result:

ok not smol

Test #7:

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

input:

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

output:

not smol

result:

ok not smol

Test #8:

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

input:

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

output:

not smol

result:

ok not smol

Test #9:

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

input:

200 300
64 134
92 154
82 142
33 198
26 185
24 74
32 144
26 118
113 122
98 130
74 84
70 184
45 181
44 136
44 134
67 185
77 160
21 50
80 181
62 78
196 199
37 174
91 105
17 74
158 166
26 172
70 129
128 133
152 173
15 86
37 67
55 91
45 74
60 141
179 184
22 168
65 161
62 67
117 152
174 181
35 99
80 103
3...

output:

not smol

result:

ok not smol

Test #10:

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

input:

200 1000
19 159
64 180
15 88
82 136
22 57
92 200
86 87
176 194
57 106
116 179
101 128
27 137
41 71
35 139
48 153
177 178
80 131
9 156
29 122
101 148
88 163
90 116
16 72
8 166
100 116
97 161
19 143
78 163
23 119
104 146
91 161
52 66
183 196
29 123
84 86
41 109
65 76
82 161
138 182
108 156
35 94
101 1...

output:

not smol

result:

ok not smol

Test #11:

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

input:

200 5000
60 81
22 145
156 181
27 44
49 89
69 176
61 64
16 199
46 50
75 103
26 168
6 35
60 75
51 117
41 105
20 154
69 100
75 195
22 115
67 72
170 190
31 115
10 200
51 129
14 147
161 163
9 72
22 113
70 87
112 184
28 81
178 197
72 180
171 192
71 116
71 174
30 95
20 157
50 125
142 184
18 130
82 110
65 1...

output:

not smol

result:

ok not smol

Test #12:

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

input:

500 300
201 309
17 37
39 176
416 493
86 475
163 215
127 283
122 274
107 412
7 93
294 434
335 360
50 87
364 372
55 192
341 411
236 299
286 349
79 208
137 470
141 421
21 324
4 165
232 473
367 397
400 475
30 77
177 435
116 133
115 281
416 482
198 498
300 410
173 457
176 450
157 179
402 425
219 486
39 3...

output:

147
3 4 5 6 7 176 12 354 399 17 18 20 21 22 24 202 181 30 32 34 39 43 44 242 46 86 49 50 285 52 54 55 313 60 94 64 459 67 68 73 76 78 208 81 82 85 91 92 95 96 99 101 107 395 109 110 113 183 115 116 118 120 121 122 127 128 345 159 470 140 421 403 146 370 151 152 179 158 160 258 163 353 357 173 177 48...

result:

ok vertex cover of size 147

Test #13:

score: 0
Accepted
time: 18ms
memory: 3732kb

input:

500 1000
232 237
263 478
147 353
131 318
45 109
218 452
377 436
61 326
29 372
394 484
72 374
312 449
451 461
26 113
25 188
21 282
453 484
261 295
449 489
225 422
125 168
123 449
23 211
251 484
40 185
38 304
6 337
71 142
287 356
315 413
185 411
68 111
453 457
70 187
20 183
107 361
324 466
277 483
10 ...

output:

not smol

result:

ok not smol

Test #14:

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

input:

500 5000
78 84
13 468
95 135
258 447
258 267
226 321
132 282
238 355
194 248
75 485
325 390
46 182
156 284
272 289
204 361
15 228
322 448
410 430
35 317
227 386
325 398
207 443
36 280
73 153
117 459
396 494
234 430
140 199
49 357
26 128
177 210
15 231
351 379
357 484
299 489
376 454
177 377
228 331
...

output:

not smol

result:

ok not smol

Test #15:

score: 0
Accepted
time: 705ms
memory: 6680kb

input:

500 124750
260 435
24 351
41 342
79 458
63 342
463 485
313 372
88 486
300 435
144 440
88 480
83 373
126 356
129 486
118 416
83 138
439 447
59 222
1 162
367 487
137 286
253 261
255 451
329 461
276 328
66 184
76 441
228 492
93 396
288 420
2 424
257 318
216 342
249 474
152 200
206 485
13 332
353 406
20...

output:

not smol

result:

ok not smol

Test #16:

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

input:

20 20
12 17
15 18
14 20
3 19
11 12
5 14
6 20
2 6
13 19
6 18
3 20
13 18
8 19
1 9
4 12
1 5
10 14
10 13
10 12
7 11

output:

9
1 2 20 14 7 19 10 12 18 

result:

ok vertex cover of size 9

Test #17:

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

input:

20 40
5 12
10 17
9 15
4 7
8 17
11 12
6 16
8 11
1 15
14 18
9 17
1 6
8 14
3 5
10 15
4 18
3 20
9 14
7 19
2 12
9 19
6 18
10 20
4 13
3 14
4 8
17 18
3 15
18 20
1 17
5 9
7 14
4 9
7 20
6 7
2 7
8 15
13 15
4 16
2 18

output:

10
1 7 3 13 12 16 8 9 10 18 

result:

ok vertex cover of size 10

Test #18:

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

input:

20 70
3 4
4 8
7 17
2 7
5 7
3 15
1 16
5 10
13 20
10 19
7 15
8 9
6 16
11 20
18 19
3 5
6 17
1 5
9 11
4 12
15 18
1 15
18 20
5 18
8 14
1 14
10 20
8 17
7 9
13 14
6 14
11 19
4 7
5 8
13 19
4 6
6 9
2 18
10 14
2 10
6 20
12 14
10 15
2 8
1 19
14 18
11 17
3 9
16 18
1 17
11 16
6 19
7 19
13 16
8 19
7 14
12 15
1 2
...

output:

10
1 7 3 11 10 6 8 12 13 18 

result:

ok vertex cover of size 10

Test #19:

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

input:

110 50
48 64
54 66
9 76
53 54
54 99
50 100
98 100
48 83
48 63
16 103
87 110
14 110
45 57
71 103
99 103
11 54
38 110
57 102
29 110
2 107
44 110
94 100
9 46
24 32
47 88
36 57
24 34
63 100
12 48
59 103
9 15
2 103
21 57
54 62
12 103
47 108
11 107
54 106
47 75
9 64
24 95
38 100
78 107
48 60
2 9
9 59
39 4...

output:

10
107 9 103 24 57 47 48 100 54 110 

result:

ok vertex cover of size 10

Test #20:

score: 0
Accepted
time: 38ms
memory: 3700kb

input:

110 300
43 59
21 78
41 53
8 37
51 55
10 58
36 81
51 105
8 104
69 101
15 84
8 29
4 69
8 83
53 54
51 54
64 69
61 69
50 53
15 46
43 47
51 108
29 69
57 81
16 18
51 109
8 99
18 37
1 43
10 96
15 95
10 14
15 107
8 50
36 51
51 78
81 94
10 66
12 51
69 102
43 63
27 81
8 72
15 44
14 53
43 54
28 69
43 68
69 108...

output:

10
8 10 15 18 21 81 53 43 51 69 

result:

ok vertex cover of size 10

Test #21:

score: 0
Accepted
time: 49ms
memory: 3888kb

input:

110 700
42 93
34 45
52 109
26 102
34 100
34 43
57 87
33 34
25 88
42 50
34 62
36 95
60 106
21 87
81 87
99 106
42 56
1 8
78 87
25 48
42 43
8 68
8 104
14 42
13 34
35 109
99 109
39 42
35 102
26 106
42 57
22 42
97 102
1 95
95 100
45 102
31 102
22 34
59 87
82 96
20 106
25 69
8 77
13 25
25 63
49 96
34 57
8...

output:

10
8 25 102 34 95 42 109 87 106 96 

result:

ok vertex cover of size 10

Test #22:

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

input:

200 500
9 78
21 41
6 189
106 172
73 198
124 154
71 111
24 77
3 22
193 194
143 187
147 192
11 127
35 49
5 60
139 161
52 96
14 51
28 163
57 105
12 154
155 159
153 187
130 133
71 132
15 95
5 29
119 153
78 96
117 159
69 170
180 188
147 151
28 62
3 142
52 77
1 192
62 68
75 135
8 191
145 187
114 157
91 14...

output:

100
1 93 3 4 5 178 7 191 61 10 12 91 20 15 126 100 116 81 72 162 24 25 26 41 147 45 164 32 142 49 46 167 37 38 39 190 42 43 44 47 67 78 51 52 158 55 125 127 132 62 63 64 65 174 170 128 87 73 117 135 186 163 189 137 171 84 150 86 88 89 90 145 139 193 184 104 105 106 173 122 109 144 111 112 157 118 11...

result:

ok vertex cover of size 100

Test #23:

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

input:

200 3000
109 154
86 90
5 157
30 132
114 162
133 160
88 151
40 112
33 36
76 142
69 171
81 118
115 144
65 128
33 192
178 182
44 91
51 98
94 111
29 122
62 109
8 72
122 195
165 175
74 104
116 126
94 114
139 170
6 192
168 169
67 190
59 64
110 186
62 148
49 180
33 141
81 88
102 165
1 120
116 180
33 111
34...

output:

100
1 108 3 4 119 118 35 8 103 112 11 12 186 85 184 16 49 143 19 91 61 190 23 24 25 26 27 28 29 30 31 111 128 36 189 159 191 43 172 45 46 88 48 82 51 178 53 55 78 57 58 155 60 62 169 64 165 138 141 173 70 71 73 75 115 105 80 176 83 193 86 87 89 158 157 101 187 104 133 113 114 116 179 164 147 199 161...

result:

ok vertex cover of size 100

Test #24:

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

input:

200 8000
149 157
84 176
17 73
100 132
25 181
171 200
16 35
5 78
97 126
113 171
24 184
117 143
40 108
96 192
9 139
109 179
101 161
114 127
156 167
14 161
128 156
71 190
51 183
51 140
74 104
119 151
65 71
158 174
138 161
160 192
9 158
27 67
55 162
100 102
159 174
63 81
47 195
40 148
36 121
107 181
33 ...

output:

100
1 2 162 54 5 141 7 20 139 10 11 60 79 46 129 16 73 100 19 21 86 169 24 85 178 67 28 29 30 31 32 124 105 36 37 38 98 108 41 42 59 182 148 195 126 112 183 52 62 194 57 58 61 81 185 65 75 177 69 115 190 72 118 155 80 140 83 176 135 133 89 104 91 111 164 120 192 161 130 157 109 110 116 119 117 123 1...

result:

ok vertex cover of size 100

Test #25:

score: 0
Accepted
time: 56ms
memory: 3736kb

input:

500 500
271 342
280 463
424 444
322 342
200 239
239 358
449 469
239 269
54 63
98 342
375 488
245 449
338 342
18 63
188 359
274 280
3 449
239 241
75 239
42 239
280 425
375 486
8 280
95 388
321 342
39 280
95 487
219 449
188 312
188 417
270 424
92 375
264 280
59 280
188 444
79 399
188 418
320 424
156 3...

output:

10
63 399 95 188 239 342 280 375 424 449 

result:

ok vertex cover of size 10

Test #26:

score: 0
Accepted
time: 158ms
memory: 3768kb

input:

500 1000
9 316
133 491
9 89
55 82
247 480
133 364
139 317
168 411
60 168
339 365
247 279
72 488
55 160
5 339
247 343
60 81
247 483
55 76
139 494
168 374
168 215
21 339
81 500
81 374
143 391
55 207
37 55
168 253
205 391
9 92
2 168
9 70
55 441
9 278
168 335
437 488
9 396
391 411
55 318
81 161
2 247
27...

output:

10
9 55 81 488 133 139 391 168 247 339 

result:

ok vertex cover of size 10

Test #27:

score: 0
Accepted
time: 291ms
memory: 3912kb

input:

500 4000
34 440
276 370
287 292
23 449
23 400
34 179
44 317
23 115
30 34
276 388
88 129
276 415
165 300
123 249
300 445
122 287
276 431
283 484
30 283
23 169
276 460
170 270
164 283
123 397
23 263
129 175
208 287
300 315
170 292
66 170
287 375
126 276
287 441
287 487
88 287
300 418
262 276
44 206
11...

output:

10
23 34 44 129 123 300 170 276 283 287 

result:

ok vertex cover of size 10

Test #28:

score: 0
Accepted
time: 28ms
memory: 3744kb

input:

500 500
12 25
334 479
235 352
343 496
120 445
178 477
93 477
124 364
55 294
222 463
29 191
18 107
38 97
142 451
29 78
237 438
98 196
26 234
16 189
15 311
297 339
107 300
176 442
218 222
8 396
335 336
456 474
276 495
130 350
59 498
18 441
303 376
308 357
10 35
114 470
403 476
234 282
132 372
6 37
179...

output:

188
1 2 3 4 37 8 9 116 11 66 13 47 15 16 17 107 19 20 22 23 24 25 26 27 28 29 30 31 32 178 34 35 36 38 293 41 42 43 44 45 46 332 52 424 487 294 56 57 59 390 441 377 217 65 196 71 420 213 419 75 137 79 234 81 112 445 86 87 257 92 93 94 440 381 97 100 157 102 103 105 379 109 154 113 470 434 291 120 18...

result:

ok vertex cover of size 188

Test #29:

score: 0
Accepted
time: 1534ms
memory: 3848kb

input:

500 3000
27 174
78 179
309 321
33 313
219 225
203 316
30 149
266 270
106 350
369 463
74 433
54 398
82 296
276 430
291 419
122 412
343 427
76 163
113 398
147 482
113 263
56 411
383 396
115 149
161 276
130 207
163 297
191 283
2 68
25 419
120 414
133 409
308 321
235 476
89 176
46 130
80 113
293 405
52 ...

output:

200
1 68 210 4 190 12 247 14 16 327 351 19 20 62 23 280 25 374 27 28 222 30 32 313 371 36 37 229 42 129 46 58 48 132 50 51 400 53 398 184 56 57 324 63 253 71 72 73 433 92 76 77 78 484 80 296 469 495 395 87 176 90 498 287 172 361 242 193 199 357 106 107 437 273 249 365 112 263 315 115 464 159 444 414...

result:

ok vertex cover of size 200

Test #30:

score: -100
Time Limit Exceeded

input:

500 8000
94 339
209 235
86 449
123 181
230 282
69 341
199 324
21 194
7 72
36 379
75 234
73 84
233 379
148 377
32 56
5 264
111 453
246 475
32 96
202 433
235 328
49 298
104 346
349 427
243 484
104 380
10 477
303 318
57 90
84 347
65 442
188 212
318 323
283 404
127 463
26 490
58 160
430 456
21 147
5 35
...

output:


result: