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>
#define eb emplace_back
using namespace std;
const int MAXN = 200055;
vector<int> G[MAXN];
int prt[MAXN], dep[MAXN];
int A[MAXN], O[MAXN];
int N, D, Ans;
void f(int i) {
if(A[i] < 2) return;
int l = A[i]-1;
for(int v : G[i]) if(A[v] < l) {
A[v] = l;
f(v);
}
}
int main() {
ios::sync_with_stdio(false);
cin >> N >> D;
for(int i = 1; i < N; i++) {
cin >> prt[i];
dep[i] = dep[prt[i]] + 1;
G[prt[i]].eb(i);
G[i].eb(prt[i]);
}
iota(O, O+N, 0); sort(O, O+N, [&](int a, int b) {
return dep[a] > dep[b];
});
for(int oi = 0, i; oi < N; oi++) {
i = O[oi];
if(!A[i]) {
Ans++;
A[i] = D;
f(i);
}
}
cout << Ans << endl;
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... |