This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector <int> g[200001];
pair <int, int> dfs(int nod = 0) {
vector <int> v;
int ret = 1;
v.push_back(0);
for (auto &i : g[nod]) {
pair <int, int> aux = dfs(i);
v.push_back(aux.first);
ret += aux.second;
}
sort(v.begin(), v.end());
int i = 0;
while (v.size() - i > 1 && v[i] + v[i + 1] < k)
i++, ret--;
return {v[i] + 1, ret};
}
int main() {
cin >> n >> k;
for (int i = 1; i < n; i++) {
int x;
cin >> x;
g[x].push_back(i);
}
cout << dfs().second;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |