# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1166894 | tch1cherin | Cat in a tree (BOI17_catinatree) | C++17 | 45 ms | 9800 KiB |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, D;
cin >> N >> D;
vector<vector<int>> G(N);
for (int i = 1; i < N; i++) {
int P;
cin >> P;
G[P].push_back(i);
}
int ans = N;
vector<int> x(N);
for (int i = N - 1; i >= 0; i--) {
for (int j : G[i]) {
if (++x[j] + x[i] < D) {
--ans;
x[i] = max(x[i], x[j]);
} else {
x[i] = min(x[i], x[j]);
}
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |