# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
924889 | 2024-02-10T03:11:57 Z | Faisal_Saqib | Cat in a tree (BOI17_catinatree) | C++17 | 0 ms | 348 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]=1; 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]=max(dp[x][j],dp[x][j+1]); dp[x][j]=max(1,dp[x][j]); } } 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]<<endl; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |