Submission #924888

# Submission time Handle Problem Language Result Execution time Memory
924888 2024-02-10T03:06:37 Z Faisal_Saqib Cat in a tree (BOI17_catinatree) C++17
0 / 100
1 ms 600 KB
#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

catinatree.cpp: In function 'int main()':
catinatree.cpp:40:6: warning: unused variable 'ans' [-Wunused-variable]
   40 |  int ans=0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -