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 + 5;
int n, d;
int H[MAXN], A[MAXN];
vector <int> Adj[MAXN];
void DFS(int node, int p = -1)
{
for(auto x : Adj[node])
{
if(x == p)
{
continue;
}
H[x] = H[node] + 1;
DFS(x, node);
}
}
void Find(int node)
{
if(A[node] == 1)
{
return;
}
for(auto x : Adj[node])
{
if(A[x] < A[node] - 1)
{
A[x] = A[node] - 1;
Find(x);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> d;
for(int i = 1; i < n; i++)
{
int p;
cin >> p;
Adj[p].push_back(i);
Adj[i].push_back(p);
}
DFS(0);
vector <int> id;
for(int i = 0; i < n; i++)
{
id.emplace_back(i);
}
sort(id.begin(), id.end(), [](int x, int y)
{
return H[x] > H[y];
});
int ans = 0;
for(auto x : id)
{
if(!A[x])
{
A[x] = d;
ans++;
Find(x);
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |