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 N = 2e5 + 2;
vector<int>adj[N];
vector<int>vis(N, 0);
int freq[N];
int n, d;
void dfs(int prev, int cur){
freq[vis[cur]]++;
for(auto &nxt: adj[cur]){
if(prev == nxt) continue;
vis[nxt] = (vis[cur] + 1) % d;
dfs(cur, nxt);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> d;
for(int i = 1; i < n; i++){
int p; cin >> p;
adj[i].push_back(p);
adj[p].push_back(i);
}
for(int i = 0; i <= n; i++){
if(adj[i].size() == 1){
dfs(-1, i);
break;
}
}
int ans = 0;
for(int i = 0; i < d; i++){
ans = max(ans, freq[i]);
}
cout << ans << '\n';
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... |