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> nei[N];
int dp[N][N], D;
void dfs(int u){
dp[u][0] = 1;
for (int i : nei[u]){
dfs(i);
int mx = 0;
for (int d = 1;d<=D;d++){
mx = max(mx,dp[u][D - d]);
int k = min(d,D - d);
dp[u][k] = max(dp[u][k],dp[i][d-1] + mx);
}
}
}
int main(){
int n;
cin>>n>>D;
for (int i=2;i<=n;i++){
int p;
cin>>p;
nei[p + 1].push_back(i);
}
dfs(1);
for (int i=0;i<=n;i++)
cout<<dp[1][i]<<'\n';
}
// next
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |