| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 924888 | Faisal_Saqib | Cat in a tree (BOI17_catinatree) | C++17 | 1 ms | 600 KiB | 
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 <iostream>
#include <vector>
using namespace std;
const int N=1501;
vector<int> ma[N];
int dp[N][N];
int d;
int n;
void dfs(int x,int p=-1)
{
	for(int y:ma[x])
		if(y!=p)
			dfs(y,x);
	dp[x][0]=0;
	for(int j=n;j>=1;j--)
	{
		dp[x][j]=0;
		for(int c:ma[x])
		{
			dp[x][j]+=dp[c][j-1];
			dp[x][j]+=(j==1);
		}
		dp[x][j]=max(dp[x][j],dp[x][j+1]);
	}
}
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>d;
	for(int i=2;i<=n;i++)
	{
		int p;
		cin>>p;
		p++;
		ma[p].push_back(i);
		ma[i].push_back(p);
	}
	int ans=0;
	dfs(1);
	if(d>=n)
	{
		cout<<1<<endl;
	}
	else
	{
		cout<<dp[1][d]+1<<endl;
	}
	return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
