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;
const int MAXN=2e5+6;
int cnt,d;
vector<int>g[MAXN];
void dfs(int u,int par,int depth)
{
if(depth%d==0)cnt++;
for(auto v:g[u])
{
if(v==par)continue;
dfs(v,u,depth+1);
}
}
int n;
int main()
{
cin>>n>>d;
for(int i=1;i<n;i++)
{
int x;
cin>>x;
g[x].push_back(i);
g[i].push_back(x);
}
int ans=0;
for(int i=0;i<n;i++)
{
cnt=0;
dfs(i,-1,0);
ans=max(ans,cnt);
}
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... |