제출 #924922

#제출 시각아이디문제언어결과실행 시간메모리
924922UmairAhmadMirzaCat in a tree (BOI17_catinatree)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; int const N=1505; vector<int> adj[N]; int opt[N][N]; int n,D; int sm[N]; void dfs(int node){ for(int i=0;i<D;i++) sm[i]=0; for(auto i:adj[node]) dfs(i); for(auto i:adj[node]) for(int k=0;k<D;k++) sm[k]+=opt[i][k]; // cout<<"node := "<<node<<endl; //mark the node for(int k=D-1;k>=1;k--){ for(int i:adj[node]){ int cal=opt[i][k-1]; cal+=(sm[max(k,D-k)-1]-opt[i][max(k,D-k)-1]); // cout<<k<<' '<<i<<' '<<(sm[max(k,D-k)-1]-opt[i][max(k,D-k)-1])<<endl; opt[node][k]=max(opt[node][k],cal); } opt[node][k]=max(opt[node][k],opt[node][k+1]); } opt[node][0]=max(1+sm[D-1],opt[node][1]); // for(int i=0;i<D;i++) // cout<<opt[node][i]<<' '; // cout<<endl; } int main(){ cin>>n>>D; for(int i=1;i<n;i++){ int a; cin>>a; adj[a].push_back(i); } if(D>=n){ cout<<1<<endl; return 0; } dfs(0); cout<<opt[0][0]<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...