QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227530 | #2569. Kill All Termites | JooDdae | WA | 2ms | 5932kb | C++20 | 503b | 2023-10-27 17:29:29 | 2023-10-27 17:29:30 |
Judging History
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;
if(n <= 2) return cout << 1, 0;
for(int i=2;i<=n;i++) {
int p; cin >> p;
v[p].push_back(i);
}
dfs(1);
cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5764kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5748kb
input:
2 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5756kb
input:
8 1 1 2 1 2 3 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 2ms
memory: 5796kb
input:
3 1 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 2ms
memory: 5916kb
input:
4 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5700kb
input:
5 1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 0ms
memory: 5916kb
input:
6 1 2 2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 2ms
memory: 5932kb
input:
7 1 2 1 4 3 4
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5744kb
input:
9 1 1 2 3 1 4 2 7
output:
2
result:
ok 1 number(s): "2"
Test #10:
score: 0
Accepted
time: 0ms
memory: 5688kb
input:
10 1 2 3 3 1 2 3 7 9
output:
2
result:
ok 1 number(s): "2"
Test #11:
score: 0
Accepted
time: 1ms
memory: 5740kb
input:
11 1 1 2 1 5 6 7 3 3 2
output:
2
result:
ok 1 number(s): "2"
Test #12:
score: 0
Accepted
time: 0ms
memory: 5696kb
input:
12 1 1 3 3 2 1 4 7 4 8 10
output:
2
result:
ok 1 number(s): "2"
Test #13:
score: 0
Accepted
time: 2ms
memory: 5764kb
input:
13 1 1 3 4 1 4 4 3 6 1 1 4
output:
2
result:
ok 1 number(s): "2"
Test #14:
score: 0
Accepted
time: 1ms
memory: 5704kb
input:
14 1 2 3 2 4 1 4 7 3 9 7 8 4
output:
3
result:
ok 1 number(s): "3"
Test #15:
score: 0
Accepted
time: 1ms
memory: 5924kb
input:
100 1 2 1 1 3 6 5 5 4 8 4 4 3 14 10 14 8 13 12 18 8 3 7 1 12 10 9 17 26 30 21 11 29 19 20 25 17 10 9 26 6 40 42 29 2 24 14 25 6 41 47 24 21 46 28 8 30 2 19 41 54 43 23 1 65 21 19 35 58 8 71 59 12 2 13 4 16 7 22 58 26 44 1 12 14 80 19 12 43 77 21 54 41 94 37 61 28 82 30
output:
19
result:
ok 1 number(s): "19"
Test #16:
score: 0
Accepted
time: 1ms
memory: 5748kb
input:
100 1 2 3 4 4 6 7 8 9 10 11 10 13 14 15 16 17 17 19 19 15 22 23 15 13 26 27 28 29 30 30 32 28 26 13 36 37 38 39 40 41 42 43 44 45 45 47 48 48 48 51 47 44 54 43 56 56 58 59 60 60 59 63 64 64 66 66 64 69 70 56 72 73 72 75 76 77 42 40 80 40 82 83 83 85 85 85 88 89 88 91 40 38 37 95 96 95 95 2
output:
17
result:
ok 1 number(s): "17"
Test #17:
score: 0
Accepted
time: 1ms
memory: 5732kb
input:
1000 1 2 3 3 5 6 7 8 9 10 11 12 11 14 15 16 16 18 19 19 21 22 23 22 21 26 27 28 29 30 31 28 27 27 35 26 37 38 39 40 41 42 43 44 41 40 47 39 18 50 51 52 53 54 55 56 57 58 59 60 60 58 57 64 65 66 67 66 65 70 71 72 73 72 64 76 76 78 79 80 56 82 18 84 84 86 86 88 88 14 14 92 14 94 94 96 96 98 98 100 101...
output:
169
result:
ok 1 number(s): "169"
Test #18:
score: 0
Accepted
time: 2ms
memory: 5772kb
input:
1000 1 2 2 2 2 2 7 2 2 2 2 2 2 2 15 15 15 2 2 2 21 1 23 23 25 25 23 1 1 1 31 31 31 31 31 31 31 1 39 40 39 42 43 42 42 42 39 39 39 50 50 39 39 54 54 39 57 57 39 60 60 60 60 60 60 39 67 67 69 67 67 67 67 39 75 75 77 77 75 75 75 39 39 39 85 39 39 39 39 39 91 91 93 39 95 95 95 98 98 95 95 95 103 103 105...
output:
152
result:
ok 1 number(s): "152"
Test #19:
score: -100
Wrong Answer
time: 1ms
memory: 5768kb
input:
1000 1 2 3 4 5 6 7 8 7 10 11 11 10 14 6 4 17 17 19 20 3 22 23 23 25 26 23 28 29 30 31 32 33 33 31 36 37 31 3 2 41 42 43 44 42 46 47 48 49 50 51 48 53 54 53 56 57 57 59 60 60 62 63 64 64 66 66 59 69 70 71 70 69 74 75 75 53 78 79 78 78 82 83 53 85 86 86 88 88 88 85 85 85 47 95 96 97 98 99 100 101 100 ...
output:
180
result:
wrong answer 1st numbers differ - expected: '181', found: '180'