QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687613 | #7684. Sweet Sugar | xcyyyyy | WA | 2ms | 5684kb | C++20 | 871b | 2024-10-29 19:59:43 | 2024-10-29 19:59:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define N 1000005
#define fr first
#define se second
#define pii pair<int,int>
int n,k,a[N];
vector<int> G[N];
pii f[N][2];
pii operator + (const pii &x,const pii &y){
return {x.fr+y.fr,x.se+y.se};
}
void dfs(int u,int fa){
f[u][0]={0,0};
f[u][a[u]&1]={0,a[u]};
for(int v:G[u])if(v^fa){
pii g0=f[u][0],g1=f[u][1];
dfs(v,u);
f[u][0]=max(g0+f[v][0],g1+f[v][1]);
f[u][1]=max(g1+f[v][0],g0+f[v][1]);
}
if(f[u][k&1].se>=k)f[u][0]=max(f[u][0],pii{f[u][k&1].fr+1,0});
}
void sol(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)G[i].clear();
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1,u,v;i<n;i++){
scanf("%d%d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1,0);
cout<<max(f[1][1].fr,f[1][0].fr)<<endl;
}
int main(){
int t;scanf("%d",&t);while(t--)sol();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 5684kb
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 2 1 0
result:
wrong answer 2nd numbers differ - expected: '0', found: '2'