QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322978#7936. Eliminate TreeAnwar_Gehad_Maghraby#WA 65ms30772kbC++20829b2024-02-08 02:38:222024-02-08 02:38:23

Judging History

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

  • [2024-02-08 02:38:23]
  • 评测
  • 测评结果:WA
  • 用时:65ms
  • 内存:30772kb
  • [2024-02-08 02:38:22]
  • 提交

answer

/**
 *    author:  MaGnsi0
 *    created: 07.02.2024 20:06:23
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    vector<set<int>> adj(n);
    for (int i = 0; i < n - 1; ++i) {
        int u; cin >> u; u--;
        int v; cin >> v; v--;
        adj[u].emplace(v);
        adj[v].emplace(u);
    }
    int ans = 0;
    function<int(int, int)> dfs = [&](int v, int p) {
        int collected = 0;
        for (int u : adj[v]) {
            if (u == p) { continue; }
            collected += dfs(u, v);
        }
        if (collected == 0) {
            return 1;
        } else {
            ans += 2 * (collected - 1) + 1;
            return 0;
        }
    };
    dfs(0, -1);
    cout << ans;
}

詳細信息

Test #1:

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

input:

5
1 2
2 3
3 4
3 5

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

4
1 2
2 3
3 4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 65ms
memory: 30772kb

input:

196666
32025 108673
181779 17115
162570 134230
93003 39673
89144 1269
185919 154408
34896 65369
35860 44720
55698 1390
45520 189805
147867 124511
135459 132555
87303 18031
176314 59695
33352 130640
87272 39716
35749 108807
143493 94486
126512 116598
40212 70895
132216 80855
22241 188737
150354 17346...

output:

138180

result:

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