QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618106#7685. Barkley IImulberryWA 2ms3684kbC++231.1kb2024-10-06 18:49:542024-10-06 18:49:55

Judging History

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

  • [2024-10-06 18:49:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3684kb
  • [2024-10-06 18:49:54]
  • 提交

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];
        g[0] = max(dp[x][0] + dp[v][0], dp[x][1] + dp[v][1]);
        g[1] = max(dp[x][1] + dp[v][0], 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] = 0;
    }
}
void solve() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        dp[i][0] = dp[i][1] = 0;
    }
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (!x) continue;
        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: 0
Wrong Answer
time: 2ms
memory: 3684kb

input:

2
5 4
1 2 2 3 4
5 10000
5 2 3 4 1

output:

1
1

result:

wrong answer 1st numbers differ - expected: '2', found: '1'