QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116345#6659. 외곽 순환 도로 21kri6 24ms22696kbC++141.7kb2023-06-28 15:45:152023-06-28 15:45:19

Judging History

你现在查看的是测评时间为 2023-06-28 15:45:19 的历史记录

  • [2024-08-26 15:50:23]
  • 管理员手动重测本题所有提交记录
  • 测评结果:6
  • 用时:19ms
  • 内存:23312kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 15:45:19]
  • 评测
  • 测评结果:6
  • 用时:24ms
  • 内存:22696kb
  • [2023-06-28 15:45:15]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cassert>
#include <map>
#define ll long long
#define inf 1000000000000000000ll
using namespace std;
int n,depth[100005];
vector<int> e[100005];
vector<ll> c,w;
int l[100005],r[100005];
int tot,id[100005],o[100005];
ll a[100005];
int m,u[100005],v[100005];
ll val[100005];
void dfs(int now,ll s){
	if (e[now].size()==0){
		l[now]=tot;
		id[tot]=now;
		++tot;
		r[now]=tot;
		u[m]=l[now],v[m]=r[now],val[m]=s;
		m++;
		return;
	}
	l[now]=tot;
	for (int i=0;i<(int)e[now].size();i++)
		if (e[now].size()>1)dfs(e[now][i],c[e[now][i]]);
		else dfs(e[now][i],min(s,c[e[now][i]]));
	r[now]=tot;
	if (now!=0&&e[now].size()>1){
		u[m]=l[now],v[m]=r[now],val[m]=s;
		m++;
	}
	return;
}
int dsu[100005],t[100005];
ll mn[100005];
int dsu_find(int x){
	if (x==dsu[x])return x;
	return dsu[x]=dsu_find(dsu[x]);
}
ll place_police(vector<int> P, vector<ll> _c, vector<ll> _w){
	n=(int)P.size()+1;
	for (int i=1;i<n;i++)e[P[i-1]].push_back(i),depth[i]=depth[P[i-1]]+1;
	c.resize(n);
	c[0]=inf;
	for (int i=1;i<n;i++)c[i]=_c[i-1]; 
	w=_w;
	dfs(0,inf);
	for (int i=0;i<tot;i++)
		if ((depth[id[i]]&1)==(depth[id[(i+1)%tot]]&1))o[(i+1)%tot]=1,a[(i+1)%tot]=w[i];
		else o[(i+1)%tot]=0,a[(i+1)%tot]=w[i];
	ll ans=inf;
	for (int i=0;i<(1<<m);i++){
		for (int j=0;j<tot;j++)dsu[j]=j,t[j]=o[j],mn[j]=a[j];
		ll s=0;
		for (int j=0;j<m;j++){
			if (!(i&(1<<j)))continue;
			s+=val[j];
			int x=dsu_find(u[j]),y=dsu_find(v[j]);
			if (x!=y){
				t[x]^=t[y],mn[x]=min(mn[x],mn[y]);
				t[y]=mn[y]=0;
				dsu[y]=x;
			} 
		}
		for (int j=0;j<tot;j++)
			if (j==dsu_find(j))
				if (t[j]==1)s+=mn[j];
		ans=min(ans,s);
	}
	return ans;
}

详细

Subtask #1:

score: 6
Accepted

Test #1:

score: 6
Accepted
time: 1ms
memory: 7784kb

input:

5
0 452912
0 820899
0 79369
0 232463
1000000000000 1000000000000 1000000000000 1000000000000

output:

532281

result:

ok single line: '532281'

Test #2:

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

input:

6
0 581451
0 68556
0 918465
0 661406
0 41816
1000000000000 1000000000000 1000000000000 1000000000000 1000000000000

output:

1000000110372

result:

ok single line: '1000000110372'

Test #3:

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

input:

4
0 0
0 0
0 0
0 0 0

output:

0

result:

ok single line: '0'

Test #4:

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

input:

5
0 938777585449
0 576051802364
0 418735407836
0 823692221300
233950071687 338912182863 866023804654 680391493800

output:

1333076973323

result:

ok single line: '1333076973323'

Test #5:

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

input:

6
0 938777585449
0 576051802364
0 418735407836
0 823692221300
0 233950071687
338912182863 866023804654 680391493800 876313612238 476765859230

output:

991597662386

result:

ok single line: '991597662386'

Test #6:

score: 0
Accepted
time: 17ms
memory: 19316kb

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

3

result:

ok single line: '3'

Test #7:

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

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 19ms
memory: 19384kb

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

3

result:

ok single line: '3'

Test #9:

score: 0
Accepted
time: 10ms
memory: 15828kb

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

50

result:

ok single line: '50'

Test #10:

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

input:

7
0 1
1 1
0 1
0 1
4 1
0 1
1000000000000 1000000000000 1000000000000 1000000000000

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 15ms
memory: 18212kb

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

1000000000000

result:

ok single line: '1000000000000'

Test #12:

score: 0
Accepted
time: 10ms
memory: 17012kb

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

1000000000023

result:

ok single line: '1000000000023'

Test #13:

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

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

1000000000000

result:

ok single line: '1000000000000'

Test #14:

score: 0
Accepted
time: 13ms
memory: 16844kb

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

1000000000023

result:

ok single line: '1000000000023'

Test #15:

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

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

23

result:

ok single line: '23'

Test #16:

score: 0
Accepted
time: 19ms
memory: 21508kb

input:

99995
0 800351
1 590567
2 404564
3 601685
4 802526
5 784654
6 558749
7 760258
8 655714
9 864130
10 678664
11 983868
12 396629
13 637742
14 592018
15 810308
16 889529
17 914966
18 623197
19 97239
20 448357
21 67877
22 785864
23 177614
24 242659
25 301722
26 5175
27 418269
28 213547
29 417295
30 80595...

output:

23

result:

ok single line: '23'

Test #17:

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

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

3249113

result:

ok single line: '3249113'

Test #18:

score: 0
Accepted
time: 13ms
memory: 18532kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

484857763484

result:

ok single line: '484857763484'

Test #19:

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

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

0

result:

ok single line: '0'

Test #20:

score: 0
Accepted
time: 7ms
memory: 16928kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

86963587131

result:

ok single line: '86963587131'

Test #21:

score: 0
Accepted
time: 16ms
memory: 19384kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

3249113

result:

ok single line: '3249113'

Test #22:

score: 0
Accepted
time: 17ms
memory: 15884kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

484861012597

result:

ok single line: '484861012597'

Test #23:

score: 0
Accepted
time: 19ms
memory: 15400kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

72033520

result:

ok single line: '72033520'

Test #24:

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

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

87023183814

result:

ok single line: '87023183814'

Test #25:

score: 0
Accepted
time: 24ms
memory: 22412kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

3249113

result:

ok single line: '3249113'

Test #26:

score: 0
Accepted
time: 21ms
memory: 22696kb

input:

99995
0 307516682495
1 677180705676
2 900093321878
3 855950595166
4 60373551204
5 97525179732
6 859433105930
7 470206852651
8 836315525302
9 68512632833
10 862923859868
11 74601760822
12 219027891391
13 839738396803
14 169708425659
15 592509244955
16 824764053219
17 619446917083
18 422190804040
19 8...

output:

3249113

result:

ok single line: '3249113'

Test #27:

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

input:

4
0 9
0 8
0 0
9 9 9

output:

9

result:

ok single line: '9'

Subtask #2:

score: 0
Time Limit Exceeded

Test #28:

score: 0
Time Limit Exceeded

input:

99997
0 122727
0 267270
0 846212
0 454122
0 805668
0 614161
0 7805
0 173284
0 684707
0 269129
0 930945
0 1101
0 992427
0 297412
0 759787
0 227130
0 120418
0 90914
0 333684
0 46144
0 519912
0 171490
0 823586
0 121787
0 674177
0 560254
0 753090
0 853359
0 465464
0 655527
0 631303
0 919012
0 597126
0 1...

output:

Unauthorized output

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #36:

score: 5
Accepted
time: 2ms
memory: 6180kb

input:

11
0 9
0 8
2 0
3 7
3 1
2 6
0 0
7 7
7 1
9 6
1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000

output:

1

result:

ok single line: '1'

Test #37:

score: -5
Time Limit Exceeded

input:

50311
0 630582
1 458618
2 300543
3 566041
4 306718
5 134260
6 736322
7 458543
8 609374
9 355623
10 706939
11 48588
12 455725
13 105118
14 71071
15 528699
16 423538
17 471781
18 98063
19 169099
20 657181
21 295537
22 49937
23 306612
24 186582
25 505763
26 831500
27 406268
28 294626
29 128111
30 42115...

output:

Unauthorized output

result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Time Limit Exceeded

Test #77:

score: 0
Time Limit Exceeded

input:

50311
0 962897543825
1 887020369743
2 363658802934
3 481009844166
4 1099712574
5 858320882162
6 521927434762
7 379344260539
8 73024776148
9 634183458545
10 869560347910
11 81581323331
12 750044298516
13 307013017409
14 306226274039
15 423923546601
16 482114694167
17 849292461119
18 299993045938
19 7...

output:

Unauthorized output

result:


Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%