QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691046#7936. Eliminate TreeKowerKoint#WA 136ms14468kbC++23616b2024-10-31 09:33:352024-10-31 09:34:16

Judging History

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

  • [2024-10-31 09:34:16]
  • 评测
  • 测评结果:WA
  • 用时:136ms
  • 内存:14468kb
  • [2024-10-31 09:33:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int N;
vector<int> e[200000];

int ans = 0;
int dfs(int v, int p) {
  int remain = 0;
  for (auto i : e[v]) {
    if (i == p) continue;
    remain += dfs(i, v);
  }
  if (remain == 0)
    return 1;
  else {
    ans += (remain - 1) * 2;
    ans++;
    return 0;
  }
}

int main() {
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }

  int remain = dfs(0, -1);
  if (remain == 1) ans++;
  cout << ans << endl;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3608kb

input:

5
1 2
2 3
3 4
3 5

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

4
1 2
2 3
3 4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 136ms
memory: 14468kb

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:

138181

result:

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