Submission #361923

#TimeUsernameProblemLanguageResultExecution timeMemory
361923ogibogi2004Cat in a tree (BOI17_catinatree)C++14
0 / 100
4 ms4972 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...