QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#117532#6659. 외곽 순환 도로 2kshitij_sodani5 28ms21576kbC++143.4kb2023-07-01 15:36:482023-07-01 15:36:49

Judging History

你现在查看的是测评时间为 2023-07-01 15:36:49 的历史记录

  • [2024-08-26 15:50:40]
  • 管理员手动重测本题所有提交记录
  • 测评结果:5
  • 用时:28ms
  • 内存:22328kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-01 15:36:49]
  • 评测
  • 测评结果:5
  • 用时:28ms
  • 内存:21576kb
  • [2023-07-01 15:36:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long llo;
//#define endl '\n'

#include <vector>

llo n;
llo co=0;
llo co2=0;
vector<pair<llo,llo>> adj[100001];
llo val[100001];
void dfs(llo no,llo par=-1,llo levv=0){
	llo st=0;
	for(auto j:adj[no]){
		if(j.a!=par){
			st=1;
			dfs(j.a,no,levv^1);
		}
	}
	if(adj[no].size()==0){

		val[no]=(co^levv);
		//cout<<no<<":"<<val[no]<<endl;
		co^=1;
		co2++;
	}
}
llo dp2[100001][3][2];
llo cot[3][2];
void dfs2(llo no,llo par=-1){

	for(int i=0;i<3;i++){
		for(int k=0;k<2;k++){
			dp2[no][i][k]=0;
		}
	}
	int st=0;

	for(auto j:adj[no]){
		dfs2(j.a,no);
		for(int i=0;i<3;i++){
			for(int k=0;k<2;k++){
				cot[i][k]=0;
			}
		}
	//	cot[0][0]=dp2[no][0][0]+min(dp2[j.a][2][0],min(dp2[j.a][0][0],dp2[j.a][1][0]+j.b));
	//	cot[1][0]=dp2[no][1][0]+min(dp2[j.a][2][0],min(dp2[j.a][1][0],dp2[j.a][0][0]+j.b));

		//cot[0][1]=min(dp2[no][0][0]+min(dp2[j.a][2][1],min(dp2[j.a][0][1],dp2[j.a][1][1]+j.b)),dp2[no][0][1]+min(dp2[j.a][2][0],min(dp2[j.a][0][0],dp2[j.a][1][0]+j.b)));
		//cot[1][1]=min(dp2[no][1][0]+min(dp2[j.a][2][1],min(dp2[j.a][1][1],dp2[j.a][0][1]+j.b)),dp2[no][1][1]+min(dp2[j.a][2][0],min(dp2[j.a][1][0],dp2[j.a][0][0]+j.b)));
		for(int i=0;i<2;i++){
			for(int k=0;k<2;k++){
				if(i>k){
					continue;
				}
				cot[0][max(i,k)]=dp2[no][0][i]+min(dp2[j.a][0][k],min(dp2[j.a][1][k]+j.b,dp2[j.a][2][k]));
				cot[1][max(i,k)]=dp2[no][1][i]+min(dp2[j.a][1][k],min(dp2[j.a][0][k]+j.b,dp2[j.a][2][k]));
				cot[2][max(i,k)]=dp2[no][2][i]+min(dp2[j.a][2][k],min(dp2[j.a][1][k],dp2[j.a][0][k])+j.b);
			}
		}
	/*	cot[0][1]=dp2[no][0][0]+min(dp2[j.a][2][1],min(dp2[j.a][0][1],dp2[j.a][1][1]+j.b));
		cot[1][1]=dp2[no][1][0]+min(dp2[j.a][2][1],min(dp2[j.a][1][1],dp2[j.a][0][1]+j.b));

		cot[2][0]=dp2[no][2][0]+min(dp2[j.a][0][0]+j.b,min(dp2[j.a][1][0]+j.b,dp2[j.a][2][0]));
		llo aa=min(dp2[j.a][0][0]+j.b,min(dp2[j.a][1][0]+j.b,dp2[j.a][2][0]));
		llo bb=min(dp2[j.a][0][1]+j.b,min(dp2[j.a][1][1]+j.b,dp2[j.a][2][1]));

		cot[2][1]=min(dp2[no][2][0]+bb,aa+dp2[no][2][1]);*/
		for(int i=0;i<3;i++){
			for(int k=0;k<2;k++){
				dp2[no][i][k]=cot[i][k];
			}
		}
		st=1;
		
	}

	if(st==0){
		dp2[no][val[no]][0]=1e16;
		dp2[no][1-val[no]][1]=1e16;
		dp2[no][2][0]=1e16;
		dp2[no][2][1]=1e16;
	}
	else{
	//	cout<<no<<":"<<dp2[no][0]<<":"<<dp2[no][1]<<endl;
	}
}


/*void dfs3(int no,int par=-1){
	dp[no][0]=0;
	dp[no][1]=0;
	int st=0;

	for(auto j:adj[no]){
		if(j.a!=par){
			dfs3(j.a,no);
			dp[no][0]+=min(dp[j.a][0],dp[j.a][1]+j.b);
			dp[no][1]+=min(dp[j.a][1],dp[j.a][0]+j.b);
			st=1;
		}
	}

	if(st==0){
		dp[no][val[no]]=1e16;
	}
	else{
	//	cout<<no<<":"<<dp[no][0]<<":"<<dp[no][1]<<endl;
	}
}*/
long long place_police(vector<int> pp, vector<long long> aa, vector<long long> bb){
	n=pp.size()+1;
	for(llo i=0;i<pp.size();i++){
		adj[pp[i]].pb({i+1,aa[i]});
	}
	dfs(0);
	dfs2(0);
	/*return min(min(dp[0][0],dp[0][1]),dp[0][2]);
	if(n==50311){
		while(true){
			continue;
		}
	}*/
	llo ans=1e18;
	for(int i=0;i<3;i++){
		for(int j=0;j<co+1;j++){
			ans=min(ans,dp2[0][i][j]);
		}
	}
	if(co==1){
		ans+=(llo)1e12;
	}
	return ans;
/*	if(co==1){
		dfs2(0);
		//cout<<no<<":"<<endl;
		

	}
	else{
		dfs2(0);
		//dfs3(0);
		return min(dp2[0][2][0],min(dp2[0][0][0],dp2[0][1][0]));
	}
    return 0;*/
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

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

output:

532281

result:

ok single line: '532281'

Test #2:

score: -6
Wrong Answer
time: 1ms
memory: 7428kb

input:

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

output:

1000000729962

result:

wrong answer 1st lines differ - expected: '1000000110372', found: '1000000729962'

Subtask #2:

score: 0
Wrong Answer

Test #28:

score: 8
Accepted
time: 19ms
memory: 17044kb

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:

24980330181

result:

ok single line: '24980330181'

Test #29:

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

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:

24980330181

result:

ok single line: '24980330181'

Test #30:

score: -8
Wrong Answer
time: 19ms
memory: 16860kb

input:

99998
0 792854
0 622829
0 836127
0 847372
0 71732
0 241096
0 487224
0 696890
0 899047
0 845614
0 27226
0 270985
0 698890
0 64699
0 856738
0 685434
0 766150
0 540443
0 802763
0 874879
0 250532
0 834015
0 616087
0 771638
0 262098
0 458015
0 959723
0 408130
0 880649
0 456673
0 923653
0 969100
0 439032
...

output:

1025045618544

result:

wrong answer 1st lines differ - expected: '1025006589524', found: '1025045618544'

Subtask #3:

score: 5
Accepted

Test #36:

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

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: 0
Accepted
time: 13ms
memory: 14028kb

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:

813491

result:

ok single line: '813491'

Test #38:

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

input:

99992
0 630582
0 458618
2 300543
2 566041
4 306718
4 134260
6 736322
6 458543
8 609374
8 355623
10 706939
10 48588
12 455725
12 105118
14 71071
14 528699
16 423538
16 471781
18 98063
18 169099
20 657181
20 295537
22 49937
22 306612
24 186582
24 505763
26 831500
26 406268
28 294626
28 128111
30 42115...

output:

0

result:

ok single line: '0'

Test #39:

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

input:

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

output:

1645133792

result:

ok single line: '1645133792'

Test #40:

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

input:

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

output:

2120124996

result:

ok single line: '2120124996'

Test #41:

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

input:

71756
0 630582
1 458618
0 300543
3 566041
4 306718
4 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
16 169099
20 657181
12 295537
22 49937
23 306612
24 186582
25 505763
26 831500
26 406268
28 294626
23 128111
30 42115...

output:

1787349034

result:

ok single line: '1787349034'

Test #42:

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

input:

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

output:

1645924769

result:

ok single line: '1645924769'

Test #43:

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

input:

68356
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:

1434056469

result:

ok single line: '1434056469'

Test #44:

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

input:

99998
0 989885
1 623358
2 323898
3 418387
4 847431
5 998077
6 737652
7 214051
8 72927
9 817696
10 494815
11 349489
12 264272
13 60664
14 739563
15 744355
16 882267
17 957314
18 547277
19 714547
20 566081
21 593766
22 431363
23 249609
24 768570
25 985859
26 183057
27 840222
28 168478
29 16211
30 3082...

output:

2654008

result:

ok single line: '2654008'

Test #45:

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

input:

99997
0 955101
1 576100
2 127659
3 811226
4 41161
4 566231
6 943952
7 287921
8 995827
9 53909
10 446266
11 568843
12 813723
12 241044
12 619032
15 744341
15 255358
15 8997
18 425939
18 28355
20 747884
21 827659
21 772961
23 229078
24 638934
24 618689
24 795722
27 518058
28 691526
29 667781
30 259093...

output:

10977059663

result:

ok single line: '10977059663'

Test #46:

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

input:

99998
0 349154
0 960228
2 693946
3 247696
3 58262
5 799702
5 731306
7 501447
8 296672
8 812371
10 173737
10 91929
12 524275
12 13376
14 316834
14 77773
16 888284
17 491488
18 963488
19 57028
20 526164
21 289556
22 136189
22 471245
24 474182
24 398669
26 46490
27 40395
28 529585
29 627410
30 271602
3...

output:

4656503217

result:

ok single line: '4656503217'

Test #47:

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

input:

99998
0 989885
1 623358
0 323898
3 418387
4 847431
4 998077
6 737652
7 214051
8 72927
8 817696
10 494815
11 349489
11 264272
13 60664
13 739563
15 744355
16 882267
11 957314
18 547277
19 714547
20 566081
21 593766
21 431363
23 249609
24 768570
25 985859
26 183057
27 840222
28 168478
28 16211
26 3082...

output:

5211108945

result:

ok single line: '5211108945'

Test #48:

score: 0
Accepted
time: 25ms
memory: 16860kb

input:

99998
0 989885
1 623358
2 323898
1 418387
4 847431
4 998077
4 737652
1 214051
8 72927
9 817696
10 494815
11 349489
10 264272
10 60664
8 739563
8 744355
16 882267
17 957314
18 547277
19 714547
20 566081
20 593766
20 431363
18 249609
24 768570
25 985859
26 183057
25 840222
28 168478
28 16211
30 30820
...

output:

7300156968

result:

ok single line: '7300156968'

Test #49:

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

input:

99999
0 960228
1 693946
1 247696
3 58262
3 799702
5 731306
5 501447
3 296672
8 812371
9 173737
10 91929
11 524275
12 13376
12 316834
11 77773
15 888284
15 491488
10 963488
18 57028
19 526164
19 289556
18 136189
22 471245
22 474182
9 398669
25 46490
26 40395
27 529585
28 627410
29 271602
30 109358
31...

output:

10004154233

result:

ok single line: '10004154233'

Test #50:

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

input:

99998
0 349154
1 960228
1 693946
1 247696
4 58262
5 799702
5 731306
5 501447
5 296672
5 812371
5 173737
5 91929
5 524275
5 13376
5 316834
4 77773
16 888284
16 491488
16 963488
16 57028
16 526164
16 289556
16 136189
16 471245
16 474182
16 398669
4 46490
27 40395
27 529585
27 627410
27 271602
27 10935...

output:

20125634322

result:

ok single line: '20125634322'

Test #51:

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

input:

99998
0 349154
1 960228
1 693946
1 247696
1 58262
1 799702
1 731306
1 501447
1 296672
1 812371
1 173737
11 91929
12 524275
12 13376
12 316834
12 77773
12 888284
12 491488
12 963488
12 57028
12 526164
12 289556
12 136189
12 471245
12 474182
12 398669
12 46490
12 40395
12 529585
12 627410
12 271602
12...

output:

23556910464

result:

ok single line: '23556910464'

Test #52:

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

input:

99998
0 349154
1 960228
1 693946
1 247696
1 58262
1 799702
1 731306
1 501447
1 296672
1 812371
1 173737
1 91929
1 524275
1 13376
1 316834
1 77773
1 888284
1 491488
1 963488
1 57028
1 526164
1 289556
22 136189
1 471245
1 474182
1 398669
1 46490
1 40395
1 529585
1 627410
1 271602
1 109358
1 83447
1 19...

output:

24381300470

result:

ok single line: '24381300470'

Test #53:

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

input:

99998
0 349154
1 960228
2 693946
3 247696
4 58262
5 799702
6 731306
6 501447
8 296672
9 812371
10 173737
11 91929
10 524275
13 13376
13 316834
15 77773
16 888284
17 491488
15 963488
19 57028
15 526164
9 289556
9 136189
9 471245
5 474182
25 398669
26 46490
27 40395
28 529585
29 627410
29 271602
31 10...

output:

5869311889

result:

ok single line: '5869311889'

Test #54:

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

input:

99999
0 960228
1 693946
2 247696
3 58262
4 799702
5 731306
6 501447
7 296672
8 812371
9 173737
9 91929
9 524275
12 13376
12 316834
14 77773
15 888284
15 491488
17 963488
18 57028
19 526164
20 289556
21 136189
22 471245
23 474182
24 398669
25 46490
23 40395
27 529585
28 627410
29 271602
29 109358
23 ...

output:

5391164384

result:

ok single line: '5391164384'

Test #55:

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

input:

99999
0 960228
1 693946
2 247696
3 58262
4 799702
5 731306
6 501447
7 296672
8 812371
9 173737
10 91929
11 524275
12 13376
13 316834
14 77773
15 888284
16 491488
17 963488
18 57028
19 526164
20 289556
21 136189
22 471245
23 474182
24 398669
25 46490
26 40395
27 529585
28 627410
29 271602
30 109358
3...

output:

4579960285

result:

ok single line: '4579960285'

Test #56:

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

input:

99997
0 955101
1 576100
1 127659
3 811226
4 41161
5 566231
6 943952
7 287921
8 995827
9 53909
9 446266
9 568843
12 813723
12 241044
14 619032
15 744341
16 255358
17 8997
18 425939
19 28355
20 747884
20 827659
22 772961
22 229078
24 638934
25 618689
25 795722
27 518058
28 691526
29 667781
29 259093
2...

output:

7479580481

result:

ok single line: '7479580481'

Subtask #4:

score: 0
Wrong Answer

Dependency #3:

100%
Accepted

Test #57:

score: 0
Wrong Answer
time: 0ms
memory: 13944kb

input:

50313
0 671723
1 730984
2 799869
3 708040
4 711347
5 913917
6 751372
7 466548
8 886178
9 550034
10 657744
11 417284
12 757271
13 462274
14 539467
15 622147
16 989468
17 588888
18 834040
19 6615
20 192481
21 495240
22 784027
23 951846
24 129510
25 204593
26 599793
27 171885
28 475383
29 206677
30 889...

output:

1000000920518

result:

wrong answer 1st lines differ - expected: '1000000629830', found: '1000000920518'

Subtask #5:

score: 0
Wrong Answer

Test #77:

score: 0
Wrong Answer
time: 11ms
memory: 14020kb

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:

1101662670212

result:

wrong answer 1st lines differ - expected: '939418184213', found: '1101662670212'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%