QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618125#7684. Sweet SugarmulberryWA 125ms3664kbC++231.4kb2024-10-06 18:58:272024-10-06 18:58:28

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 18:58:28]
  • 评测
  • 测评结果:WA
  • 用时:125ms
  • 内存:3664kb
  • [2024-10-06 18:58:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
vector<int> g[N];
int dp[N][2];
int n, k, ans;
void dfs(int x, int fa) {
    for (auto v : g[x]) {
        if (v == fa) continue;
        dfs(v, x);
        vector<int> g(2);
        g[0] = dp[x][0], g[1] = dp[x][1];
        if (dp[x][0] != -1 && dp[v][0] != -1) g[0] = max(g[0], dp[x][0] + dp[v][0]);
        if (dp[x][1] != -1 && dp[v][1] != -1) g[0] = max(g[0], dp[x][1] + dp[v][1]);
        if (dp[x][1] != -1 && dp[v][0] != -1) g[1] = max(g[1], dp[x][1] + dp[v][0]);
        if (dp[x][0] != -1 && dp[v][1] != -1) g[1] = max(g[1], dp[x][0] + dp[v][1]);
        dp[x][0] = g[0];
        dp[x][1] = g[1];
    }
    if (dp[x][k & 1] >= k) {
        ans++;
        dp[x][0] = dp[x][1] = -1;
    }
}
void solve() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        dp[i][0] = dp[i][1] = -1;
    }
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (!x)
            dp[i][0] = dp[i][1] = 0;
        else
            dp[i][x & 1] = x;
    }
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    ans = 0;
    dfs(1, 0);
    cout << ans << '\n';
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3652kb

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: 3648kb

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: 125ms
memory: 3664kb

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
3
0
1
2
2
1
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
2
0
1
1
1
1
1
1
0
1
1
1
0
3
1
0
1
1
0
4
0
0
0
1
1
0
0
1
0
2
0
5
1
0
0
0
0
0
0
0
0
1
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 24th numbers differ - expected: '2', found: '3'