QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#624376#6438. Crystalflywwww22#WA 1ms7748kbC++201.2kb2024-10-09 15:42:172024-10-09 15:42:17

Judging History

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

  • [2024-10-09 15:42:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7748kb
  • [2024-10-09 15:42:17]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define fo(i,a,b) for(ll (i)=(a);(i)<=(b);(i)++)
#define fd(i,a,b) for(ll (i)=(a);(i)>=(b);(i)--)
#define eb emplace_back
using namespace std;
const int N=1e5+10;
ll a[N],t[N],f[N],g[N],h[N][2];
vector<int> e[N];
void dfs(int x,int fa)
{
	ll sum=0,mA=0,tmp;
	for(auto y:e[x]){
		if(y==fa) continue;
		dfs(y,x);
		sum+=f[y]-a[y];
		mA=max(mA,a[y]);
		tmp=2*a[y]+g[y]-f[y];
		
		if(tmp>h[x][0]){
			h[x][1]=h[x][0];
			h[x][0]=tmp;
		}
		else if(tmp>h[x][1]) h[x][1]=tmp;
	}
	f[x]=max(f[x],sum+mA+a[x]);
	for(auto y:e[x])
	{
		if(y==fa) continue;
		g[x]+=f[y];
		if(t[y]==3)
		{
			tmp=2*a[y]+g[y]-f[y];
			if(tmp==h[x][0])
			{
				f[x]=max(f[x],a[x]+a[y]+sum+h[x][1]);
			}
			else 
			{
				f[x]=max(f[x],a[x]+a[y]+sum+h[x][0]);
			}
		}
	}
}
int n;
void solve()
{
	cin>>n;
	fo(i,1,n) cin>>a[i];
	fo(i,1,n) {
		h[i][0]=h[i][1]=0;
		f[i]=g[i]=0;
		e[i].clear();
		cin>>t[i];	
	}
	int x,y;
	fo(i,2,n) {
		cin>>x>>y;
		e[x].eb(y);
		e[y].eb(x);
	}
	dfs(1,0);
	cout<<f[1]<<"\n";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T=1;
	cin>>T;
	while(T--) solve();
	return 0;
} 
/*
5
1 1 1 1 1
3 3 1 3 1
1 2
1 3
2 4
2 5	
*/

詳細信息

Test #1:

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

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: 1ms
memory: 7748kb

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
24
24
62
31
15
16
28
19
19

result:

wrong answer 4th numbers differ - expected: '56', found: '62'