QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#673415 | #7684. Sweet Sugar | i0stream | WA | 43ms | 11996kb | C++14 | 1.5kb | 2024-10-24 22:15:34 | 2024-10-24 22:15:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+100;
int dp[N][2],a[N],n,T,k,u,v,ans;
int E,head[N],to[N<<1],nxt[N<<1];
int read(){
int flag=1,x=0,c=getchar();
while (c<'0' || c>'9'){if (c=='-') flag=-1;c=getchar();}
while (c>='0' && c<='9') x=x*10+c-48,c=getchar();
return x*flag;
}
void addedge(int u,int v){
to[++E]=v;
nxt[E]=head[u];
head[u]=E;
}
inline int calc(int x,int y){
if (x==-1 && y==-1) return -1;
if (x==-1) return y;
if (y==-1) return x;
return x+y;
}
void sol(int &x,int &y,int t){
if (t&1) y=max(y,t);
else x=max(x,t);
}
void dfs(int u,int F){
int t=a[u]&1;
dp[u][t]=a[u];dp[u][t^1]=-1;
for (int e=head[u];e;e=nxt[e]){
int v=to[e];
if (v==F) continue;
dfs(v,u);
int u0=-1,u1=-1,p;
p=calc(dp[u][0],dp[v][0]);
if (p!=-1) sol(u0,u1,p);
p=calc(dp[u][0],dp[v][1]);
if (p!=-1) sol(u0,u1,p);
p=calc(dp[u][1],dp[v][0]);
if (p!=-1) sol(u0,u1,p);
p=calc(dp[u][1],dp[v][1]);
if (p!=-1) sol(u0,u1,p);
dp[u][0]=u0;dp[u][1]=u1;
}
//cout<<u<<' '<<dp[u][0]<<" "<<dp[u][1]<<endl;
if (dp[u][k&1]>=k){
//cout<<u<<endl;
ans++;
dp[u][0]=-1;
dp[u][1]=-1;
}
}
int main(){
T=read();
while (T--){
n=read();k=read();
E=0;ans=0;
for (int i=0;i<=n+10;i++) head[i]=0,dp[i][0]=-1,dp[i][1]=-1;
for (int i=0;i<=n*2+10;i++) to[i]=0,nxt[i]=0;
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<n;i++){
u=read();v=read();
addedge(u,v);addedge(v,u);
}
dfs(1,0);
printf("%d\n",ans);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11996kb
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: 11996kb
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: 43ms
memory: 11936kb
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 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 1 1 1 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 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 73rd numbers differ - expected: '1', found: '2'