QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#358945 | #7684. Sweet Sugar | Graygoo | WA | 151ms | 29928kb | C++14 | 1.2kb | 2024-03-20 09:34:06 | 2024-03-20 09:34:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
vector<int> to[1000005];
#define pii pair<int,int>
pii f[1000005][2];
pii tmp[2];
int a[1000005];
int n,k;
pii add(pii a,pii b){return make_pair(a.first+b.first,a.second+b.second);}
void dfs(int x,int fa){
for(auto v:to[x]){
if(v==fa)continue;
dfs(v,x);
}
tmp[0]=tmp[1]=f[x][0]=f[x][1]={INT_MIN,INT_MIN};
if(a[x]%2==0)tmp[0]={0,a[x]};
else tmp[1]={0,a[x]};
for(auto v:to[x]){
if(v==fa)continue;
pii x0=tmp[0],x1=tmp[1];
tmp[0]=max(add(x0,f[v][0]),add(x1,f[v][1]));
tmp[1]=max(add(x0,f[v][1]),add(x1,f[v][0]));
}
tmp[0]=max(tmp[0],make_pair(0,0));
for(int i=0;i<=1;i++){
f[x][i]=max(f[x][i],tmp[i]);
if(i==k%2 and tmp[i].second>=k)f[x][0]=max(f[x][0],make_pair(tmp[i].first+1,0));
}
return ;
}
void solve(){
cin>>n>>k;
for(int i=1;i<=n;i++)to[i].clear();
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<n;i++){
int u,v;cin>>u>>v;
to[u].push_back(v);
to[v].push_back(u);
}
dfs(1,0);
cout<<max(f[1][0].first,f[1][1].first)<<endl;
return ;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
int t;cin>>t;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 29928kb
input:
4 7 5 1 2 1 2 2 1 2 1 2 2 3 3 4 3 5 5 6 5 7 2 2 1 0 1 2 1 1 1 1 2 1
output:
2 0 1 0
result:
ok 4 number(s): "2 0 1 0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 27348kb
input:
12 1 1 0 1 1 1 1 1 2 1 2 0 1 2 1 1 2 2 1 3 0 1 3 1 1 3 2 1 2000000 0 1 2000000 1 1 2000000 2
output:
0 1 0 0 0 1 0 0 0 0 0 0
result:
ok 12 numbers
Test #3:
score: -100
Wrong Answer
time: 151ms
memory: 27032kb
input:
200000 5 2 1 1 0 0 1 2 4 5 2 4 1 3 2 5 1 0 0 0 0 0 5 1 1 2 3 2 5 4 5 3 1 0 0 0 1 1 4 4 2 3 4 5 2 5 9 1 0 0 0 2 4 3 2 1 3 1 5 1 5 3 0 1 1 0 1 5 4 2 1 4 3 5 1 5 1 0 2 1 1 1 5 3 2 4 3 4 1 4 5 1 1 0 1 1 0 1 5 4 2 1 3 5 2 5 7 0 2 1 1 2 5 1 2 3 2 5 5 4 5 5 0 1 0 1 0 2 4 4 3 5 2 1 5 5 1 0 0 1 0 1 4 1 4 5 2...
output:
1 0 0 0 1 3 3 0 0 2 0 0 2 1 0 0 1 1 0 2 0 1 0 2 1 0 0 0 0 0 1 2 0 0 2 2 0 1 0 0 0 0 2 3 0 0 1 1 2 1 2 0 4 0 1 1 0 1 0 0 1 5 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 3 1 0 1 0 0 4 0 0 0 1 1 0 0 1 0 2 0 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 1 0 1 0 1 1 1 2 0 1 2 0 0 2 0 0 1 0 0 0 0 0 ...
result:
wrong answer 43rd numbers differ - expected: '3', found: '2'