QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#250737 | #6438. Crystalfly | hhoppitree# | WA | 3ms | 34264kb | C++14 | 1.4kb | 2023-11-13 16:27:38 | 2023-11-13 16:27:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
long long F[N][2],G[N];
int a[N],t[N],n;
vector<int>to[N];
void dfs(int u,int f)
{
long long s1=0,m1=0,m2=0,mx=0,sum=0;
F[u][0]=F[u][1]=G[u]=0;
for(int v:to[u])
{
if(v==f)continue;dfs(v,u);
F[u][0]+=F[v][0];
mx=max(mx,F[v][1]-F[v][0]);
G[u]+=F[v][0];
{
long long w=max(F[v][1]-F[v][0],0ll);
if(m1<w)m2=m1,m1=w;else m2=max(m2,w);
}
}
sum=F[u][0];
F[u][0]+=mx;
F[u][1]=F[u][0];
for(int v:to[u])
{
if(v==f)continue;
if(t[v]==3)
{
long long w=max(F[v][1]-F[v][0],0ll);
F[u][1]=max(F[u][1],sum+(m1==w?m2:m1)+G[v]+a[v]);
F[u][0]=max(F[u][0],sum+(m1==w?m2:m1)+G[v]+a[v]);
}
}
// F[u][1]=max(F[u][1],s1+s2);
F[u][1]+=a[u];
// cerr<<u<<":\t"<<F[u][0]<<"\t"<<F[u][1]<<"\t"<<G[u]<<endl;
}
int T;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
cin>>T;
while(T--)
{
cin>>n;
for(int i=1;i<=n;++i)cin>>a[i],to[i].clear();
for(int i=1;i<=n;++i)cin>>t[i];
for(int i=1,u,v;i<n;++i)
{
cin>>u>>v;
to[u].push_back(v);
to[v].push_back(u);
}
dfs(1,0);
cout<<F[1][1]<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 34140kb
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: 3ms
memory: 34264kb
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 39 25 106 31 15 16 28 19 22
result:
wrong answer 2nd numbers differ - expected: '24', found: '39'