QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743683#8643. Board Game275307894a3 1330ms9724kbC++143.7kb2024-11-13 19:48:222024-11-13 19:48:27

Judging History

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

  • [2024-11-13 19:48:27]
  • 评测
  • 测评结果:3
  • 用时:1330ms
  • 内存:9724kb
  • [2024-11-13 19:48:22]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=5e4+5,M=N*4+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const ll INF=5e18+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,m,k,X[N],w1[N],w2[N];
vector<int> S[N];
char s[N];
namespace Init{
	int d1[N],d2[N];
	void build(){
		Me(d1,0x3f);
		priority_queue<pii> q;
		for(int i=1;i<=n;i++) if(s[i]=='1') d1[i]=-2,q.emplace(2,i);
		while(!q.empty()){
			auto [w,x]=q.top();w*=-1;q.pop();
			if(w^d1[x]) continue;
			for(int i:S[x]) if(d1[i]>w+1) q.emplace(-(d1[i]=w+1),i);
		}
		Me(d2,0x3f);
		for(int i=1;i<=n;i++) if(s[i]=='1') for(int j:S[i]) if(s[j]=='1'&&d2[i]>0) d2[i]=-1,q.emplace(1,i);
		while(!q.empty()){
			auto [w,x]=q.top();q.pop();w*=-1;
			if(w^d2[x]) continue;
			for(int i:S[x]){
				int v=w+(s[i]^'1');
				if(d2[i]>v) q.emplace(-(d2[i]=v),i);
			}
		}
		// for(int i=1;i<=n;i++) if(d1[i]>=n) gdb(d1[i],d2[i]);
		for(int i=2;i<=k;i++) w1[i]=(d1[X[i]]==-2?0:d1[X[i]]),w2[i]=max(d2[X[i]]+(s[X[i]]=='1'),0);
		// gdb(d1[X[k]],w1[k]);
	}
}
ll ans[N],flag[N];
void build(){
	queue<int> q;
	static int d[N];
	Me(d,0x3f);d[X[1]]=0;q.push(X[1]);
	while(!q.empty()){
		int x=q.front();q.pop();
		if(s[x]=='1'&&x^X[1]) continue;
		for(int i:S[x]) if(d[i]>d[x]+1) d[i]=d[x]+1,q.push(i);
	}
	for(int i=1;i<=n;i++) if(d[i]<=n) ans[i]=d[i],flag[i]=1;
}
namespace Solve1{
	ll f[3005],d[N];
	void Solve(){
		Me(f,0x3f);f[0]=0;
		for(int i=2;i<=k;i++){
			gdb(w1[i],w2[i]);
			for(int j=i;~j;j--) f[j]=min(f[j]+w2[i],(j?f[j-1]:INF)+w1[i]); 
		}
		for(int i=0;i<k;i++){
			Me(d,0x3f);
			// gdb(i,f[i]);
			priority_queue<pair<ll,int> > q;
			d[X[1]]=f[i];q.emplace(-f[i],X[1]);
			while(!q.empty()){
				auto [w,x]=q.top();q.pop();w*=-1;
				if(w^d[x]) continue;
				if(!i) gdb(x,d[x]);
				for(int j:S[x]){
					ll v=w+(s[j]=='1'?i+k-1:0)+1;
					if(d[j]>v) q.emplace(-(d[j]=v),j);
				}
			}
			static ll dw[N];
			Mc(dw,d);Me(d,0x3f);
			for(int j=1;j<=n;j++)if(s[j]=='1'&&j^X[1]){
				for(int h:S[j]) if(s[h]=='0'&&dw[j]+1<d[h]) q.emplace(-(d[h]=dw[j]+1),h);
			}
			while(!q.empty()){
				auto [w,x]=q.top();q.pop();w*=-1;
				if(w^d[x]) continue;
				if(!i) gdb(x,d[x]);
				for(int j:S[x]){
					ll v=w+(s[j]=='1'?i+k-1:0)+1;
					if(d[j]>v) q.emplace(-(d[j]=v),j);
				}
			}
			for(int j=1;j<=n;j++) ans[j]=min(ans[j],d[j]-(s[j]=='1'?i+k-1:0));
			gdb(d[1],flag[1]);
			// if(f[i]<=1e9) gdb(d[585],f[i]);
		}
	}
}
void Solve(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=m;i++){
		int x,y;scanf("%d%d",&x,&y);
		S[x].push_back(y);S[y].push_back(x);
	}
	scanf("%s",s+1);
	for(int i=1;i<=k;i++) scanf("%d",&X[i]);
	Init::build();
	Me(ans,0x3f);
	build();
	if(k<=3000) Solve1::Solve();
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

详细

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 615ms
memory: 7288kb

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: 3
Accepted
time: 12ms
memory: 7892kb

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:

2610
3673
15
7659
10149
8209
878
4102
7582
10483
6418
6826
11546
12814
11394
7792
9097
7484
14575
913
5802
584
8172
961
7434
8828
14665
7642
14032
6284
8299
3040
9576
4953
47
13721
10634
3362
9103
4901
4022
11866
14548
5132
9252
13165
143
9494
2845
13149
5616
3023
13560
12315
8126
2002
5706
10657
14...

result:

ok 30000 lines

Test #3:

score: 3
Accepted
time: 19ms
memory: 8912kb

input:

50000 49999 50000
23237 38489
46903 47222
463 17722
5061 37126
21771 23294
4851 25450
408 41933
1298 5353
8952 44686
5842 17741
15835 33052
16401 17274
33117 33174
7070 24079
22424 46115
5336 6340
35165 36940
3308 36325
12014 20182
391 48629
9736 42693
5246 46582
22861 48389
3338 6669
31354 49668
11...

output:

8988
372
12633
8934
15728
15677
431
10910
20467
16345
10441
16923
12383
15090
11112
19353
21485
9819
17810
3071
41
99
8479
9616
1173
13790
1142
14800
19055
675
1086
2353
22330
18271
2373
11286
20247
21236
18133
11260
2792
19399
9049
18056
14190
3523
22890
19479
14288
9335
561
19226
12836
11409
8485
...

result:

ok 50000 lines

Test #4:

score: 3
Accepted
time: 272ms
memory: 9508kb

input:

49900 50000 100
21419 22725
19367 26559
4942 22766
16196 32249
12443 43575
17415 32668
3559 30282
6024 31186
4553 32107
1085 24970
27857 48472
15126 48937
22784 33748
16961 18301
21066 30382
41567 46191
17677 42298
2910 32294
14609 16464
14131 44143
8413 13472
17266 18767
567 48263
2410 29825
22159 ...

output:

4729
6824
18742
805
16289
4349
1296
5007
15785
15606
18374
4228
1685
19748
16689
7552
13232
5985
19529
7256
13074
6094
12823
7464
19302
3985
5081
4794
2513
6637
10664
6726
11115
11493
10542
4882
2626
10108
17287
690
8100
6464
10436
3789
14356
11646
18179
20174
19124
1188
20268
1232
4167
127
1224
166...

result:

ok 49900 lines

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 7
Accepted
time: 1330ms
memory: 7164kb

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
Wrong Answer
time: 11ms
memory: 7860kb

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:

24
115
79
159
99
71
180
64
116
142
81
167
114
82
77
198
78
113
174
176
56
201
118
96
94
101
68
230
86
143
87
114
130
176
157
148
28
33
32
118
122
158
109
111
95
94
71
193
64
80
105
104
91
71
66
84
99
106
71
63
79
110
91
156
160
170
109
104
71
90
157
52
164
119
74
64
147
34
52
30
0
100
24
92
64
119
6...

result:

wrong answer 1979th lines differ - expected: '2228338', found: '4557430888798830399'

Subtask #3:

score: 0
Wrong Answer

Test #13:

score: 7
Accepted
time: 678ms
memory: 7668kb

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
Wrong Answer
time: 14ms
memory: 8176kb

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:

85
57
80
39
77
77
60
56
36
92
75
63
85
80
77
67
16
70
86
82
70
63
80
58
64
54
64
29
20
26
67
74
88
18
86
99
47
60
82
100
67
32
58
59
77
69
61
30
59
61
65
58
49
17
64
24
36
63
88
57
53
78
100
107
63
58
69
66
78
81
1
79
71
48
75
57
18
75
72
82
18
71
47
57
80
45
40
71
17
86
82
72
69
73
82
10
40
75
30
1...

result:

wrong answer 296th lines differ - expected: '1950482', found: '4557430888798830399'

Subtask #4:

score: 0
Wrong Answer

Test #23:

score: 19
Accepted
time: 3ms
memory: 7268kb

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: 0
Wrong Answer
time: 3ms
memory: 7592kb

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:

wrong answer 1141st lines differ - expected: '31', found: '41'

Subtask #5:

score: 0
Wrong Answer

Test #44:

score: 23
Accepted
time: 43ms
memory: 9724kb

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: 0
Wrong Answer
time: 48ms
memory: 9388kb

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:

wrong answer 37405th lines differ - expected: '27', found: '31'

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #4:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%