#include <bits/stdc++.h>
using namespace std;
// yine saçma sapan şeyler :))
#define int long long
#define OYY LLONG_MAX
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define se second
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define pb push_back
#define lim 1505
typedef long long lo;
int n,d;
vector<int> v[lim];
deque<int> dp[lim];
inline bool ch(int node,int dist){
return (int)dp[node].size()-1>=dist;
}
inline void f(int node){
dp[node].pb(1);
int kim=-1,mx_sz=1;
for(auto go:v[node]){
f(go);
if(ch(go,d-1))dp[node][0]+=dp[go][d-1];
if(mx_sz<=(int)dp[go].size()){
mx_sz=(int)dp[go].size();
kim=go;
}
}
int cur=0;
for(auto go:v[node]){
if(go==kim)continue;
cur=max(cur,(int)dp[go].size());
}
if(~kim){
//cout<<kim<<" "<<dp[node][0]<<" "<<dp[kim][0]<<endl;
dp[kim].push_front(dp[node][0]);
swap(dp[kim],dp[node]);
}
cout<<kim<<" "<<" "<<node<<" "<<dp[node].size()<<" "<<dp[kim].size()<<endl;
for(auto a:dp[node]){
cout<<a<<" ";
}
cout<<endl;
for(auto go:v[node]){
cout<<dp[go].size()<<" "<<go<<endl;
}
cout<<cur<<endl;
cur++;
for(int j=1;j<=cur;j++){
int tot=0,tot2=0,maxi=0;
for(auto go:v[node]){
if(go==kim)continue;
if(ch(go,d-j-1))tot+=dp[go][d-j-1];
if(ch(go,j-1))tot2+=dp[go][j-1];
if(ch(go,j-1))maxi=max(maxi,dp[go][j-1]);
}
for(auto go:v[node]){
if(go==kim)continue;
if(ch(go,d-j-1))tot-=dp[go][d-j-1];
if(ch(go,j-1))tot+=dp[go][j-1];
if(ch(node,j) && j<=d-j)dp[node][j]=max(dp[node][j],tot);
if(ch(go,j-1))tot-=dp[go][j-1];
if(ch(go,d-j-1))tot+=dp[go][d-j-1];
}
if(j>=d-j){
dp[node][j]=max(dp[node][j],tot2);
}
}
for(int j=cur;j>=0;j--){
if(ch(node,j+1))dp[node][j]=max(dp[node][j],dp[node][j+1]);
}
}
int32_t main(){
faster
cin>>n>>d;
d=min(d,n+2);
FOR{
if(i==1)continue;
int x;cin>>x;
x++;
v[x].pb(i);
}
f(1);
int cev=0;
FOR{
cout<<i<<" ";
for(int j=0;j<(int)dp[i].size();j++){
cout<<dp[i][j]<<" ";
}
cout<<'\n';
}
cout<<cev<<endl;
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... |