QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#615393 | #7684. Sweet Sugar | zhangboju | WA | 144ms | 56384kb | C++14 | 1.2kb | 2024-10-05 18:25:42 | 2024-10-05 18:25:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 2e6 + 5;
int n, k;
vector<int> g[N];
int c[N];
int f[N][2];
bool ban_to_fa[N];
int ans;
void dfs(int u, int fa) {
f[u][0] = 0;
f[u][c[u] & 1] = c[u];
for (int v : g[u]) {
if (v == fa) continue;
dfs(v, u);
if (ban_to_fa[v]) continue;
int t0 = max(f[u][0] + f[v][0], f[u][1] + f[v][1]);
int t1 = max(f[u][0] + f[v][1], f[u][1] + f[v][0]);
f[u][0] = max(f[u][0], t0);
f[u][1] = max(f[u][1], t1);
}
if (f[u][k & 1] >= k) {
ban_to_fa[u] = 1;
++ans;
}
}
void solve() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &c[i]);
}
for (int i = 1; i < n; i++) {
int u, v;
scanf("%d%d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, -1);
printf("%d\n", ans);
}
void clear() {
ans = 0;
for (int i = 1; i <= n; i++) {
g[i].clear();
f[i][0] = f[i][1] = -1e9;
ban_to_fa[i] = 0;
}
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
solve();
clear();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 56384kb
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: 7ms
memory: 55232kb
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: 144ms
memory: 53552kb
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'