QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#440617 | #7684. Sweet Sugar | yuanyq5523 | WA | 100ms | 31116kb | C++17 | 948b | 2024-06-13 21:18:44 | 2024-06-13 21:18:45 |
Judging History
answer
#include <bits/stdc++.h>
#define endl "\n"
#define LL long long
using namespace std;
#define int long long
const int N=1e6+6;
const int INF=1e8;
vector<int>edge[N];
int n,k,ans,c[N],f[N][2];
void dfs(int u,int fa){
f[u][c[u]&1]=c[u];
for (int v:edge[u]){
if (v==fa) continue;
dfs(v,u);
int a1=max(f[u][0]+f[v][0],f[u][1]+f[v][1]);
int a2=max(f[u][0]+f[v][1],f[u][1]+f[v][0]);
f[u][0]=max(a1,max(f[u][0],f[v][0]));
f[u][1]=max(a2,max(f[u][1],f[v][1]));
}
if (f[u][k&1]>=k){
f[u][1]=f[u][0]=-INF;
ans++;
}
}
void solve(){
cin>>n>>k; ans=0;
for (int i=1;i<=n;i++){
cin>>c[i];
edge[i].clear();
f[i][0]=f[i][1]=-INF;
}
for (int i=1,u,v;i<n;i++){
cin>>u>>v;
edge[u].push_back(v);
edge[v].push_back(u);
}
dfs(1,0);
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T; cin>>T;
while (T--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 30480kb
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: 3ms
memory: 30820kb
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: 100ms
memory: 31116kb
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'