#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
const int N=2000;
int n,d;
vector<int> ma[N],vep[N];
int h[N];
bitset<N> rem;
void remove(int x,int dp=0,int p=-1)
{
// if(rem[x])
// return;
for(int y:ma[x])
{
if(y!=p)
{
remove(y,dp+1,x);
}
}
if(dp<d)
rem[x]=1;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cin>>n>>d;
int max_h=0;
for(int i=2;i<=n;i++)
{
int p;
cin>>p;
p++;
h[i]=h[p]+1;
vep[h[i]].push_back(i);
max_h=max(max_h,h[i]);
ma[p].push_back(i);
ma[i].push_back(p);
}
int ans=0;
for(int cur_h=max_h;cur_h>=0;cur_h--)
{
for(int v:vep[cur_h])
{
if(!rem[v])
{
ans++;
remove(v);
}
}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |