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;
typedef long long ll;
const int mxN = 2e5+10;
vector<int> adj[mxN];
int cnt[mxN];
int N, D;
int bfs(int st) {
memset(cnt, 0, sizeof cnt);
vector<bool> vis(N+10, 0);
queue<pair<int,int>> q;
q.push({0, st});
vis[st] = 1;
while(q.size()) {
auto node = q.front();
q.pop();
cnt[node.first]++;
for (auto it : adj[node.second]) {
if (!vis[it]) {
vis[it] = 1;
q.push({node.first+1, it});
}
}
}
int ret = 0;
for (int i = 0; i <= N; i+=D)
ret += cnt[i];
return ret;
}
void solve() {
cin >> N >> D;
for (int i = 1; i < N; i++) {
int v;
cin >> v;
adj[i].push_back(v);
adj[v].push_back(i);
}
int ans = 0;
for (int i = 0; i < N; i++) {
ans = max(ans, bfs(i));
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |