QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687789 | #6438. Crystalfly | GLLF234 | WA | 1ms | 7804kb | C++20 | 1.4kb | 2024-10-29 21:15:34 | 2024-10-29 21:15:34 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=0x7f7f7f7f;
int a[100005];
int t[100005];
int dp[100005][2];
vector<int> p[100005];
void dfs(int u,int fa){
dp[u][1]=dp[u][0]=a[u];
int mx1=-inf,mx2=-inf;
for(auto v: p[u]){
if(v==fa) continue;
dfs(v,u);
dp[u][0]+=dp[v][1]-a[v];
int temp=dp[v][0];
if(temp>mx1) mx2=mx1,mx1=temp;
else if(temp>mx2) mx2=temp;
}
for(auto v:p[u]){
if(v==fa) continue;
dp[u][1]=max(dp[u][1],dp[u][0]+a[v]);
if(t[v]==3){
// cout<<dp[u][1]<<" "<<dp[u][0]<<endl;
if(dp[v][0]==mx1) dp[u][1]=max(dp[u][1],dp[u][0]+a[v]+mx2);
else dp[u][1]=max(dp[u][1],dp[u][0]+mx1+a[v]);
}
}
// cout<<mx1<<" "<<mx2<<endl;
// cout<<dp[u][1]<<" "<<dp[u][0]<<endl;
}
void slove(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
dp[i][0]=dp[i][1]=0;
p[i].clear();
}
for(int i=1;i<=n;i++){
cin>>t[i];
}
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
p[u].push_back(v);
p[v].push_back(u);
}
dfs(1,0);
cout<<dp[1][1]<<endl;
return ;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin>>T;
while(T--){
slove();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5752kb
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: 0ms
memory: 7804kb
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'