QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#240473#6438. CrystalflysfjhRE 0ms0kbC++141.3kb2023-11-05 15:43:432023-11-05 15:43:44

Judging History

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

  • [2023-11-05 15:43:44]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-05 15:43:43]
  • 提交

answer

#include<bits/stdc++.h> 
using namespace std;
#define fer(i,a,b) for(int i=a;i<=b;i++)
#define fdr(i,a,b) for(int i=a;i>=b;i--)
#define int long long
#define xx first
#define yy second
#define pb push_back
#define ps push
#define db double
#define P pair<int,int>
#define endl '\n'
#define ll long long
const int N=2e5+10;
const int mod=1e9+7;
const int INF=1e18+10;
priority_queue<int,vector<int>,greater<int>> pq;

int n;
int t[N];
int a[N],f[N],sum[N];
vector<int> g[N];

int dfs(int u,int fa){
	int mx=0;
	multiset<int> st;
	for(int v:g[u]){
		if(v==fa) continue;
		dfs(v,u);
		sum[u]+=f[v];
		mx=max(mx,a[v]);
		if(t[v]==3LL) st.insert(a[v]);
	}
	f[u]=sum[u]+mx;
	st.insert(-INF);
	for(int v:g[u]){
		if(v==fa) continue;
		if(t[v]==3LL) st.erase(st.find(a[v]));
		f[u]=max(f[u],sum[u]-f[v]+sum[v]+a[v]+*st.rbegin());
		if(t[v]==3LL) st.insert(a[v]);
	}
}

void solve(){
	cin>>n;
	fer(i,1,n) g[i].clear(),f[i]=sum[i]=0;
	fer(i,1,n) cin>>a[i];
	fer(i,1,n) cin>>t[i];
	fer(i,1,n-1){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1,0);
	cout<<f[1]+a[1]<<endl;
	
}

signed main()
{
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	int tt;
	cin>>tt;
	while(tt--){
		solve(); 
	} 
}





















Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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:


result: