QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#264120 | #7684. Sweet Sugar | luyiming123 | WA | 145ms | 30200kb | C++14 | 911b | 2023-11-25 12:50:41 | 2023-11-25 12:50:42 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, k, c[N];
vector <int> g[N];
int dp[N][2], ans = 0;
void dfs(int x, int fa)
{
dp[x][c[x] & 1] = c[x], dp[x][!(c[x] & 1)] = -1e9;
for(int v : g[x])
{
if(v == fa) continue;
dfs(v, x);
if(dp[v][k & 1] >= k) {++ans; continue; }
int tmp[2] = {dp[x][0], dp[x][1]};
dp[x][1] = max(dp[x][0], max(dp[v][0] + tmp[1], dp[v][1] + tmp[0]));
dp[x][0] = max(dp[x][0], max(dp[v][1] + tmp[1], dp[v][0] + tmp[0]));
}
return;
}
int main(void)
{
int Test; scanf("%d", &Test);
while(Test--)
{
scanf("%d%d", &n, &k); ans = 0;
for(int i = 1; i <= n; i++) scanf("%d", &c[i]), g[i].clear();
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, 0);
if(dp[1][k & 1] >= k) ++ans;
printf("%d\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 30188kb
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: 28204kb
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: 145ms
memory: 30200kb
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 3 1 0 0 0 2 0 1 2 0 1 2 2 0 1 0 0 0 0 3 3 0 0 1 1 2 1 2 1 4 0 1 1 0 1 0 0 1 5 0 1 1 1 0 2 0 2 1 1 1 1 1 1 1 0 3 1 1 1 2 2 4 1 0 1 1 1 1 0 1 1 2 2 5 1 1 1 0 0 0 0 0 0 1 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 2 1 2 0 1 2 0 0 2 0 0 1 0 0 0 0 0 ...
result:
wrong answer 24th numbers differ - expected: '2', found: '3'