QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#402982#7684. Sweet Sugarucup-team3215#WA 145ms3640kbC++201.1kb2024-05-01 19:12:492024-05-01 19:12:50

Judging History

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

  • [2024-05-01 19:12:50]
  • 评测
  • 测评结果:WA
  • 用时:145ms
  • 内存:3640kb
  • [2024-05-01 19:12:49]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using graph = vector<vi>;
using ar = array<int, 3>;
const int INF = 1e9;

ar dfs(int u, int p, const graph & g, const vi & c, int k) {
    ar res = {c[u], 0, INF};
    for (int v : g[u]) {
        if (v == p) {
            continue;
        }
        auto [su, eaten, caneat] = dfs(v, u, g, c, k);
        res[0] += su;
        res[1] += eaten;
        res[2] = min(res[2], caneat);
    }
    if (res[0] >= k) {
        if (res[0] % 2 == k % 2 || res[0] - res[2] >= k) {
            return {0, res[1] + 1, INF};
        }
    }
    return res;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vi c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }
    graph g(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u;--v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    auto [_, ans, __] = dfs(0, 0, g, c, k);
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

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

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

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
1
0
1
0
2
1
0
0
0
0
0
1
2
0
0
2
2
0
1
0
0
0
0
1
3
0
0
1
1
2
1
2
0
4
0
0
1
0
1
0
0
1
5
0
1
1
1
0
1
0
1
1
1
1
0
1
1
1
0
3
1
0
1
0
0
2
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
0
0
0
0
0
0
...

result:

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