QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718161#6438. CrystalflyfrogmanWA 2ms8864kbC++141.4kb2024-11-06 19:51:112024-11-06 19:51:20

Judging History

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

  • [2024-11-06 19:51:20]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8864kb
  • [2024-11-06 19:51:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define int long long
vector<int> g[N];
int t[N],a[N],f[N][3];
int n;
void dfs(int x,int fa){
	f[x][0]=0;
	f[x][1]=0;
	f[x][2]=0;
	int sum=0,mx=0;
	vector<int> p,s;
	for(int i=0;i<g[x].size();++i){
		int v=g[x][i];
		if(v==fa){
			continue;
		}
		dfs(v,x);
		sum+=f[v][0];
		mx=max(mx,f[v][1]-f[v][0]);
		p.push_back(f[v][2]-f[v][0]);
		s.push_back(f[v][2]-f[v][0]);
	}
	for(int i=1;i<p.size();++i){
		p[i]=max(p[i],p[i-1]);
	}
	for(int i=s.size()-2;i>=0;--i){
		s[i]=max(s[i],s[i+1]);
	}
	f[x][2]=a[x]+sum;
	f[x][1]=sum+mx;
	f[x][0]=sum+mx;
	for(int i=0;i<g[x].size();++i){
		int v=g[x][i];
		if(v==fa){
			continue;
		}	
		if(t[v]==3){
			int y=0;
			if(i){
				y=max(y,p[i-1]);
			}
			if(i<g[x].size()-1){
				y=max(y,s[i+1]);
			}
			f[x][1]=max(f[x][1],sum+y+f[v][1]-f[v][0]);
			f[x][0]=max(f[x][0],sum+y+f[v][1]-f[v][0]);
		}
	}
	f[x][1]+=a[x];
}
inline void solve(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=n;++i){
		cin>>t[i];
	}
	for(int i=1;i<n;++i){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1,0);
	cout<<f[1][1]<<'\n';
	for(int i=1;i<=n;++i){
		g[i].clear();
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T;
	cin>>T;
	while(T--){
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7944kb

input:

2
5
1 10 100 1000 10000
1 2 1 1 1
1 2
1 3
2 4
2 5
5
1 10 100 1000 10000
1 3 1 1 1
1 2
1 3
2 4
2 5

output:

10101
10111

result:

ok 2 number(s): "10101 10111"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 8864kb

input:

10
6
8 1 1 5 8 9
2 1 2 2 2 2
1 2
2 3
2 4
1 5
2 6
6
6 4 4 1 3 6
2 1 3 3 3 3
1 2
1 3
3 4
4 5
5 6
6
10 5 1 8 5 1
1 3 1 2 2 2
1 2
2 3
2 4
2 5
3 6
10
6 8 8 9 6 9 5 6 6 4
2 1 3 3 2 2 2 2 3 1
1 2
1 3
3 4
4 5
5 6
4 7
2 8
7 9
9 10
7
10 9 1 5 7 5 4
1 1 1 2 1 3 2
1 2
1 3
3 4
3 5
5 6
1 7
5
7 1 1 4 2
3 1 3 2 2
1...

output:

25
30
24
61
36
14
17
28
19
19

result:

wrong answer 2nd numbers differ - expected: '24', found: '30'