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;
using i64 = long long;
const int inf=1e9;
const int N=200'000;
int main()
{
int n,dist;
cin>>n>>dist;
vector<int>p(n,0);
vector<deque<int>>dp(n);
for(auto &c:dp)
{
c.push_back(1);
}
for(int i=1;i<n;i++)
{
cin>>p[i];
}
for(int i=n-1;i>0;i--)
{
dp[i].push_front(0);
if((int)dp[i].size()==dist+2)
{
dp[i].pop_back();
}
deque<int>&b=dp[i],&a=dp[p[i]];
if(a.size()<b.size())
{
swap(a,b);
}
for(int i=0;i<(int)b.size();i++)
{
int remain=dist-i;
int val=b[i];
if(remain<(int)a.size())
{
val+=a[remain];
}
a[min(i,remain)]=max(a[min(i,remain)] , val);
}
for(int i=(int)b.size()-2;i>=0;i--)
{
a[i]=max(a[i],a[i+1]);
}
}
cout<<dp[0][0];
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... |