QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533002#8643. Board GameNevll#0 2595ms8328kbC++143.1kb2024-08-25 15:38:212024-08-25 15:38:24

Judging History

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

  • [2024-08-25 15:38:24]
  • 评测
  • 测评结果:0
  • 用时:2595ms
  • 内存:8328kb
  • [2024-08-25 15:38:21]
  • 提交

answer

# include <bits/stdc++.h>
# define ll long long
# define ld long double
# define pii pair<int, int>
# define fi first
# define se second
using namespace std;

// complexity : K^2 + 2K * (M log M)

int num[50001], N, M, K;
vector<int> edge[50001];
string S;
bool stop[50001], vis[100011];
ll dist[2][50001], ds[2][50001]; // 0 = dist ke yg add 1, 1 dist yg ke add 2
// kalo 1 ada yg dist 0, buat jadi 2
// kalo 0 ada yg dist 0, buat jadi 1

void build() {
	for(int i=1;i<=N;i++) {
		dist[0][i] = dist[1][i] = 1e9;
	}
	priority_queue<pii> PQ;
	for(int i=1;i<=N;i++) {
		if(!stop[i]) continue;
		bool cek = 0;
		for(auto p : edge[i]) {
			if(stop[p]) cek = 1;
		}
		if(cek) PQ.push({0, i});
	}
	for(int i=1;i<=N;i++) vis[i] = 0;
	while(PQ.size()) {
		pii x = PQ.top();
		PQ.pop();
		if(vis[x.se]) continue;
		vis[x.se] = 1;
		if(x.fi <= -1) dist[0][x.se] = -x.fi;
		else dist[0][x.se] = 1;
		
		for(auto p : edge[x.se]) {
			if(!vis[p]) {
				if(!stop[p]) PQ.push({x.fi - 1, p});
				else PQ.push({x.fi, p});
			}
		}
	}
	
	for(int i=1;i<=N;i++) vis[i] = 0;
	for(int i=1;i<=N;i++) {
		if(stop[i]) PQ.push({0, i});
	}
	while(PQ.size()) {
		pii x = PQ.top();
		PQ.pop();
		if(vis[x.se]) continue;
		vis[x.se] = 1;
		if(x.fi <= -1) dist[1][x.se] = -x.fi;
		else dist[1][x.se] = 2;
		
		for(auto p : edge[x.se]) {
			if(!vis[p]) {
				PQ.push({x.fi - 1, p});
			}
		}
	}
	
	for(int i=2;i<=K;i++) {
	//	cout<<"dist : "<<dist[0][num[i]]<<" "<<dist[1][num[i]]<<endl;
		for(int c=0;c<=2*K;c++) ds[1][c] = 1e18;
		for(int c=0;c<=2*K;c++) {
			if(c + 1 <= 2 * K) ds[1][c + 1] = min(ds[1][c + 1], ds[0][c] + dist[0][num[i]]);
			if(c + 2 <= 2 * K) ds[1][c + 2] = min(ds[1][c + 2], ds[0][c] + dist[1][num[i]]);
		}
		for(int c=0;c<=2*K;c++) ds[0][c] = ds[1][c];
	}
}

ll ans[50001];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin>>N>>M>>K;
	for(int i=0;i<M;i++) {
		int a, b;
		cin>>a>>b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	
	cin>>S;
	for(int i=0;i<N;i++) {
		stop[i + 1] = S[i] - '0';
	}
	
	for(int i=1;i<=K;i++) cin>>num[i];
	build();
	
	for(int i=1;i<=N;i++) ans[i] = 1e18;
	for(int i=0;i<=2*K;i++) {
		priority_queue< pair<pair<ll, int>, int> >PQ;
		PQ.push({{0, num[1]}, 0});
		for(int c=1;c<=2 * N + 3;c++) vis[c] = 0;
		while(PQ.size()) {
			pair<pair<ll, int>, int> x = PQ.top();
			PQ.pop();
			if(vis[2 * x.fi.se + x.se]) continue;
		//	if(i == 3) cout<<"here; "<<x.se<<" "<<x.fi.se<<" "<<x.fi.fi<<" "<<ds[0][i]<<" "<<i<<endl;
			ans[x.fi.se] = min(ans[x.fi.se], -x.fi.fi);
			vis[2 * x.fi.se + x.se] = 1;
			
			for(auto p : edge[x.fi.se]) {
			//	if(p == 11) cout<<"go to  11"<<" "<<x.se<<" "<<2 * p + 1<<" "<<vis[2 * p + 1]<<endl;
				if(x.fi.se != num[1] && stop[x.fi.se] && x.se == 0 && !vis[2 * p - 1]) PQ.push({{x.fi.fi - 1ll * ds[0][i] - 1ll, p}, -1});
				else if(x.fi.se != num[1] && stop[x.fi.se] && x.se == -1 && !vis[2 * p - 1]) PQ.push({{x.fi.fi - 1ll * i - 1ll, p}, -1});
				else if((!stop[x.fi.se] || x.fi.se == num[1]) && !vis[2 * p + x.se])PQ.push({{x.fi.fi - 1ll,  p},x.se});
			}
		}
	}
	for(int i=1;i<=N;i++) cout<<ans[i]<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 3
Accepted
time: 1201ms
memory: 6552kb

input:

3000 3000 3000
2378 2385
1560 2450
189 2980
44 1140
425 1843
167 1563
439 2010
7 951
1311 1370
1305 2085
150 1600
16 2469
431 2674
317 2191
1845 2918
2195 2917
1210 1577
125 1049
911 1160
504 2060
376 2420
1676 2969
1343 1576
284 1869
835 1989
273 1330
234 1906
1482 1524
2415 2460
388 2897
2177 2600...

output:

76
52
40
54
67
54
62
36
44
32
60
61
58
29
34
22
64
25
31
33
14
79
80
58
68
29
67
69
47
60
48
55
45
11
24
51
17
24
47
29
50
57
89
54
62
63
55
61
7
41
61
27
64
60
63
55
44
43
39
48
57
47
65
65
55
43
51
48
22
57
47
28
52
51
50
61
41
61
69
50
41
53
42
58
45
26
60
52
30
56
47
56
32
55
44
58
56
71
69
41
6...

result:

ok 3000 lines

Test #2:

score: 0
Time Limit Exceeded

input:

30000 30000 30000
11640 15443
5731 12870
5066 28442
11803 29263
2399 20658
4911 11282
676 1962
10390 19686
6117 6722
22155 28614
2932 14721
11403 13488
6697 22434
19113 26975
20347 20663
15743 16072
19116 25652
10891 19389
1373 27384
14607 29107
6192 29223
7196 10267
15467 16280
21828 26032
365 982
...

output:


result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #5:

score: 7
Accepted
time: 2595ms
memory: 5932kb

input:

3000 3000 3000
1391 1542
299 1578
1346 1528
46 1259
1513 2261
201 1717
56 1635
199 2327
847 882
1977 2161
465 1954
1723 2580
482 2105
906 2207
747 2742
2026 2845
1565 1809
295 311
278 2408
1215 2583
520 832
464 638
1223 1346
1799 2703
1022 2717
887 2160
619 2109
165 2478
879 1343
319 2463
56 815
109...

output:

25
47
29
15
51
29
39
23
47
39
23
39
27
39
5
39
19
26
30
31
43
32
39
86790
24
13
86787
52
31
24
36
22
33
31
32
22
36
43
24
25
30
32
86793
31
49
34
31
31
39
21
33
86793
34
40
23
43
44
37
32
37
48
86790
33
86783
42
46
28
86787
15
47
43
42
41
39
38
14
34
42
33
86775
24
37
36
12
14
28
47
43
34
27
45
41
1...

result:

ok 3000 lines

Test #6:

score: 0
Time Limit Exceeded

input:

30000 30000 30000
15802 26734
1581 27129
4313 12830
7001 28197
5489 10268
11838 19275
11260 21410
3519 29279
932 23073
8888 28355
17227 29224
1060 5702
20326 25420
1598 14082
15716 27167
4982 19730
4497 8783
15068 19181
7588 9083
4816 21808
15694 24819
4716 27198
14003 15119
5397 11717
3612 20613
24...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #13:

score: 7
Accepted
time: 1491ms
memory: 6056kb

input:

3000 3000 3000
997 1695
884 1068
654 1853
6 520
947 2382
787 2407
818 1795
2347 2718
46 1560
1180 2169
582 1881
1080 1766
770 2877
365 419
365 749
1315 2536
223 1867
216 545
1311 1952
1598 2796
141 620
1681 2938
301 2204
866 1710
872 961
369 466
2160 2936
2295 2359
1310 1744
1572 2088
1111 2618
1680...

output:

357
518
350
113
154
370
718
974
1389
588
1322
215
670
9
870
488
375
195
1102
149
1373
944
303
508
1217
19
920
646
699
713
1152
1247
555
751
80
50
584
1361
149
921
140
1183
989
667
455
198
180
813
472
71
112
169
331
600
666
31
860
145
1090
207
496
654
825
1330
278
112
690
1152
885
1412
94
96
771
132
...

result:

ok 3000 lines

Test #14:

score: 0
Time Limit Exceeded

input:

30000 30000 30000
5947 19048
4004 18741
10068 24221
13216 23775
14185 17633
2653 21744
87 19566
5657 19635
24673 28265
5039 14021
8019 20341
7620 25285
6719 8806
15262 25748
14231 28690
21585 29569
27254 27866
12665 29102
2884 11669
2014 11831
1927 26375
9676 21506
2114 28403
18249 27263
4937 8497
6...

output:


result:


Subtask #4:

score: 0
Wrong Answer

Test #23:

score: 19
Accepted
time: 5ms
memory: 6268kb

input:

1500 3000 2
432 1120
324 1221
37 294
50 931
588 1149
178 887
460 517
268 533
649 935
123 1291
642 1025
1145 1489
630 1375
163 1407
842 1004
155 1300
296 1049
380 840
215 1224
283 981
211 1056
75 725
325 1437
591 680
1179 1253
876 1425
382 1230
1065 1436
612 784
121 770
349 633
140 1168
443 1019
103 ...

output:

6
6
7
4
5
5
6
3
5
7
5
6
5
5
5
6
6
6
3
5
5
6
3
6
5
6
3
3
6
6
5
6
4
5
7
6
6
6
5
2
5
5
6
5
4
7
4
4
5
5
5
7
6
5
5
3
6
6
5
5
6
5
6
4
5
6
4
7
3
6
6
4
5
5
4
7
6
6
6
7
5
3
5
6
4
6
4
6
4
6
4
6
5
6
3
4
6
4
5
3
6
5
6
7
4
6
5
6
7
5
4
6
5
5
6
6
6
4
5
5
6
4
4
6
6
6
6
6
6
6
6
5
6
6
5
6
4
6
5
6
6
6
6
5
7
4
6
4
6
5
...

result:

ok 1500 lines

Test #24:

score: 19
Accepted
time: 6ms
memory: 6664kb

input:

3000 2999 5
1183 2619
603 1077
245 1639
988 1253
70 2760
2292 2975
2483 2998
851 1914
214 968
1902 2025
1636 2835
62 2320
2082 2708
267 1972
613 2739
1273 2062
2173 2928
1028 1532
417 2184
291 899
608 2280
922 1566
670 1218
1023 1213
1193 2777
1142 2410
532 1558
67 1473
1041 1652
146 1877
727 2468
5...

output:

79
79
73
72
58
44
91
58
84
78
57
26
82
33
20
109
42
73
114
63
87
59
75
42
87
117
71
56
97
17
29
87
105
40
107
143
44
41
83
101
22
13
88
97
19
40
71
70
15
113
89
97
64
90
66
112
28
88
126
56
50
17
115
17
69
83
92
23
48
135
50
53
77
71
88
87
93
54
25
15
112
69
73
30
72
66
10
66
88
67
67
90
74
78
75
28...

result:

ok 3000 lines

Test #25:

score: 19
Accepted
time: 196ms
memory: 6660kb

input:

3000 2999 376
1269 2828
540 2100
459 2192
1176 2286
1449 1461
2568 2836
511 1436
1580 2036
1623 1837
554 2879
2222 2286
1316 2997
280 337
870 1575
77 2864
10 1424
588 2960
677 2959
254 548
691 1544
346 1337
591 2329
151 1896
305 2577
742 819
1544 2646
679 2071
219 2786
1732 2454
61 1247
1535 2704
10...

output:

684
874
611
580
355
22
246
797
0
415
770
67087
853
67274
298
68077
884
433
110
68087
67193
293
67294
323
705
221
696
67242
33
62
858
242
58
67176
67031
29
67210
67036
67136
805
267
759
28
239
67064
68055
67036
336
67107
67022
316
442
234
703
766
113
373
184
68070
29
717
59
67128
214
825
409
201
6809...

result:

ok 3000 lines

Test #26:

score: 0
Wrong Answer
time: 18ms
memory: 5000kb

input:

2990 3000 25
926 979
752 2267
861 2664
92 2235
1338 1549
5 1674
394 2828
198 2419
328 1655
2230 2675
1946 2452
1460 2590
306 2972
27 1195
1755 2511
38 1631
1518 1734
2799 2869
54 514
1022 2346
410 845
491 2867
1604 2130
666 1955
817 1398
1738 2230
220 495
595 771
470 2755
413 2945
1437 2785
2545 276...

output:

89
107
162
94
121
127
152
219
163
161
97
191
127
272
188
6
189
252
203
103
318
241
204
264
325
247
242
236
95
219
195
95
156
324
51
60
8
157
217
240
0
212
60
305
186
117
62
272
87
222
251
98
282
12
221
220
299
168
216
105
277
82
191
65
161
91
253
129
246
148
167
244
129
96
129
91
127
7
59
276
271
9
...

result:

wrong answer 1st lines differ - expected: '91', found: '89'

Subtask #5:

score: 0
Wrong Answer

Test #44:

score: 23
Accepted
time: 74ms
memory: 7836kb

input:

50000 49999 2
25634 31370
8027 24849
12312 23307
3731 32856
28725 29829
23424 44542
9950 43281
17138 22049
29393 31047
24061 46387
861 3924
12114 24868
29242 36744
5090 11267
3946 26100
7151 22151
27368 49971
43548 44917
25373 45846
4117 43120
24675 34139
9043 21081
29857 41278
37558 41510
11300 402...

output:

114
120
159
152
68
38
72
118
129
123
155
95
61
164
142
103
72
58
122
97
89
73
64
57
174
59
67
114
111
99
122
60
100
61
20
112
104
103
114
168
113
70
104
93
105
49
118
119
111
177
91
88
87
102
162
146
94
178
108
87
98
130
90
152
41
71
61
145
77
79
94
70
133
80
89
124
122
105
67
38
133
173
118
126
85
...

result:

ok 50000 lines

Test #45:

score: 23
Accepted
time: 39ms
memory: 8140kb

input:

50000 49999 2
43895 48944
8580 43793
5509 33075
15981 49586
724 31051
32635 49692
4755 18049
14056 49273
29520 41218
6544 23864
43813 44446
9124 23567
7289 30800
4062 49229
35718 49417
2991 12579
4020 36609
33183 42312
2126 12426
1152 49261
33185 37634
42 3540
28164 28325
8375 41142
14587 25165
2779...

output:

22033
26533
379
6609
11251
5059
7698
25028
18355
28058
18344
19986
7376
1693
15178
13059
9315
26184
27508
16488
23505
3264
21131
3137
20079
27632
28801
11775
187
12780
26366
29802
26641
13180
7867
9604
23866
19475
4660
4123
13002
25059
21917
19394
28016
28672
19448
12000
20191
28263
8952
5688
28968
...

result:

ok 50000 lines

Test #46:

score: 23
Accepted
time: 29ms
memory: 8040kb

input:

49950 50000 2
4566 37999
20188 25612
30193 43510
25668 36562
28256 43823
20772 29329
16661 37612
70 48595
33 17367
25778 37077
4934 34483
11295 15609
7376 41523
7796 45967
26467 42262
36278 46521
25896 30329
4435 24881
15142 33287
11683 35540
18305 23196
2597 34080
2122 49079
19179 35816
18617 48301...

output:

764
8452
8468
7140
7241
8980
2754
12524
1411
13960
6656
4755
4200
9225
3500
14506
1777
5644
12460
5955
2527
5071
3412
4282
738
2690
7192
316
1911
8195
3754
2194
14991
4168
4704
15389
11089
2510
8415
5640
3920
10944
13159
11051
3133
5710
10000
2214
955
7407
2225
10109
9732
4737
9027
11810
1913
10206
...

result:

ok 49950 lines

Test #47:

score: 23
Accepted
time: 63ms
memory: 7856kb

input:

49900 50000 2
22337 34344
3402 42937
21720 34588
19022 34787
5343 18877
43238 43267
2703 20471
18279 47773
47688 48623
13892 29391
8358 23684
9414 25609
32166 34324
16261 22849
48362 48667
2505 34154
178 31736
22256 30061
20580 23750
5141 42669
22569 47226
12171 17545
3389 44447
27268 44611
20016 49...

output:

70
105
86
76
106
93
93
100
74
102
114
75
102
94
55
141
114
68
79
115
110
111
96
101
82
67
119
157
100
59
76
96
128
123
103
83
89
104
87
81
145
122
91
117
103
100
122
112
110
93
185
114
87
95
92
70
124
111
118
111
67
119
53
122
88
83
88
93
90
66
110
127
81
123
79
73
89
67
92
157
70
153
90
87
154
77
8...

result:

ok 49900 lines

Test #48:

score: 23
Accepted
time: 86ms
memory: 7984kb

input:

49900 50000 2
8945 34436
5791 11132
31531 44584
21729 40859
3593 28551
17705 23650
7484 45899
20901 44241
24239 37340
41319 48171
33711 45870
26192 48145
33147 48485
15401 17979
43789 46041
14128 23036
24414 33691
1261 9507
1602 2275
6929 33729
19562 46463
5863 25796
4545 31674
10670 39250
3973 2931...

output:

86
72
56
43
81
72
68
101
70
71
48
49
41
55
52
41
55
61
55
56
75
65
62
78
54
50
57
87
57
25
68
46
65
80
65
59
55
50
50
67
65
87
52
110
76
40
53
62
56
82
71
81
47
60
90
43
61
55
82
42
80
68
52
75
60
47
43
54
47
49
58
87
68
57
52
13
57
96
69
70
65
60
67
47
77
66
67
81
81
19
67
67
81
82
61
18
69
71
57
7...

result:

ok 49900 lines

Test #49:

score: 23
Accepted
time: 32ms
memory: 8156kb

input:

40000 50000 2
15314 17433
3269 19902
20689 23398
13792 23631
9469 35552
2011 2942
746 10547
2487 34970
10637 38858
13754 29351
4195 37154
9693 21108
16406 18812
16694 18823
18173 21541
5995 30185
27088 27533
1798 8110
5478 23675
21259 34392
17486 32860
1662 11587
13795 17385
23329 39617
5911 29267
3...

output:

2836
7313
9014
3462
7796
277
781
4615
1523
8883
1851
9220
7558
3362
6405
7328
1454
2540
4326
4869
5001
7638
8815
2451
5857
7829
5231
1596
964
8995
7490
5987
3705
8993
5950
2439
3185
3224
3959
471
1979
1740
2697
1244
5464
6605
3670
77
4659
2650
231
2274
780
3113
2665
3346
325
4842
4022
3206
5059
5000...

result:

ok 40000 lines

Test #50:

score: 0
Wrong Answer
time: 102ms
memory: 8328kb

input:

10000 50000 2
4769 8553
3189 3302
5295 5915
3232 8063
2497 2904
6120 9199
5732 5853
5566 7061
3602 3669
2483 2996
3329 9775
4918 5767
4841 9426
707 2875
7974 9037
838 7532
7718 8738
1940 4710
5055 8052
5576 5900
2474 5642
2425 5640
4743 9451
5480 7134
3055 4504
1492 2983
3403 9933
3004 9056
5167 831...

output:

4
4
5
4
4
4
4
5
4
5
5
5
4
5
4
4
5
4
4
4
5
4
4
5
5
4
4
4
4
5
2
4
5
4
5
5
4
5
4
5
3
5
4
5
4
4
4
4
5
4
4
5
5
4
4
4
5
5
4
6
4
4
3
5
5
3
4
4
4
4
5
4
5
5
5
4
5
4
5
4
4
5
3
4
4
5
5
5
5
4
4
4
5
5
4
4
3
4
4
4
4
5
5
4
4
5
4
5
5
5
4
5
4
5
3
5
4
4
5
4
4
4
2
5
4
4
4
5
5
5
4
4
5
4
5
5
5
5
4
4
5
5
4
5
5
4
4
5
4
4
...

result:

wrong answer 47th lines differ - expected: '5', found: '4'

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #4:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%