QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227528#2569. Kill All TermitesJooDdaeWA 1ms6028kbC++20462b2023-10-27 17:28:132023-10-27 17:28:13

Judging History

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

  • [2023-10-27 17:28:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6028kb
  • [2023-10-27 17:28:13]
  • 提交

answer

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

int n;
vector<int> v[100100];

int ans;

int dfs(int u) {
    if(v[u].empty()) return 1;

    int re = 0;
    for(auto x : v[u]) re += dfs(x);
    if(re > 1) ans++, re = 0;
    return re;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i=2;i<=n;i++) {
        int p; cin >> p;
        v[p].push_back(i);
    }
    cout << ans + dfs(1);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1


output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

2
1

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

8
1 1 2 1 2 3 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

3
1 1

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

4
1 1 1

output:

1

result:

ok 1 number(s): "1"

Test #6:

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

input:

5
1 1 1 1

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 5984kb

input:

6
1 2 2 2 1

output:

2

result:

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