QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#117521#6659. 외곽 순환 도로 2kshitij_sodani0 0ms7880kbC++142.8kb2023-07-01 15:18:222024-08-26 15:50:40

Judging History

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

  • [2024-08-26 15:50:40]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:0ms
  • 内存:7880kb
  • [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:18:25]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:8492kb
  • [2023-07-01 15:18:22]
  • 提交

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<1;k++){
			dp2[no][i][k]=0;
		}
	}
	int st=0;

	for(auto j:adj[no]){
		if(j.a!=par){
			dfs2(j.a,no);
			for(int i=0;i<3;i++){
				for(int k=0;k<1;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)));
			

			cot[2][0]=dp2[no][2][0]+min(dp2[j.a][0][0]+j.b,min(dp2[j.b][1][0]+j.b,dp2[j.a][2][0]));
			//llo aa=min(dp2[j.a][0][0]+j.b,min(dp2[j.b][1][0]+j.b,dp2[j.a][2][0]));
			//llo bb=min(dp2[j.a][0][1]+j.b,min(dp2[j.b][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<1;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;
	}
}
/*llo dp[100001][2];
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);
	if(n==50311){
		while(true){
			continue;
		}
	}
	return min(min(dp2[0][0][co],dp2[0][1][co]),dp2[0][2][co])+(co*(llo)1e12);
	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;
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

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

output:

Unauthorized output

result:


Subtask #2:

score: 0
Runtime Error

Test #28:

score: 0
Runtime Error

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
Runtime Error

Test #36:

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

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
Runtime Error

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
Runtime Error

Test #77:

score: 0
Runtime Error

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:

0%