QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276405 | #7684. Sweet Sugar | ship2077 | WA | 49ms | 30976kb | C++14 | 950b | 2023-12-05 20:52:08 | 2023-12-05 20:52:09 |
Judging History
answer
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
constexpr int M=1e6+5;
int n,k,x,y,ans,a[M],f[M][2];
vector<int>g[M];
int read(){
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x*f;
}
void dfs(int x,int fa){
f[x][a[x]&1]=a[x];f[x][~a[x]&1]=-1<<30;
for (auto v:g[x]){
if (v==fa) continue; dfs(v,x);
tie(f[x][0],f[x][1])=tuple<int,int>(max(f[x][0],max(f[x][1],f[x][0])+f[v][0]),
max(f[x][1],max(f[x][1],f[x][0])+f[v][1]));
}
if (f[x][0]>=k&&f[x][0]-k+1&1||f[x][1]>=k) f[x][0]=f[x][1]=0,ans++;
}
void solve(){
n=read();k=read();
for (int i=1;i<=n;i++) a[i]=read(),g[i].clear();
for (int i=1;i<n;i++){
x=read();y=read();
g[x].push_back(y);
g[y].push_back(x);
} ans=0; dfs(1,0);
printf("%d\n",ans);
}
int main(){int T=read();
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 30976kb
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: 29564kb
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: 49ms
memory: 30492kb
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 3 0 0 2 2 0 1 0 0 0 0 3 3 0 0 1 1 2 1 2 0 4 0 1 1 0 1 0 0 1 5 0 1 1 1 0 2 1 2 1 1 2 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 2 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 1 0 1 0 1 2 1 2 0 1 2 0 0 2 0 0 1 0 0 0 0 0 ...
result:
wrong answer 32nd numbers differ - expected: '2', found: '3'