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;
vector<int> adj[200005];
int n, d, s, x;
int f(int u)
{
int m=1e9;
for (int v:adj[u])
m=min(m, f(v));
if (m+1>=d)
s++, m=-1;
return m+1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> d;
for (int i=1; i<n; i++)
{
cin >> x;
adj[x].push_back(i);
}
f(0);
cout << s;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |