제출 #924895

#제출 시각아이디문제언어결과실행 시간메모리
924895Faisal_SaqibCat in a tree (BOI17_catinatree)C++17
0 / 100
0 ms348 KiB
#include <iostream> #include <vector> #include <bitset> using namespace std; const int N=2000; int n,d; vector<int> ma[N],vep[N]; int h[N]; bitset<N> rem; void remove(int x,int dp=0,int p=-1) { // if(rem[x]) // return; for(int y:ma[x]) { if(y!=p) { remove(y,dp+1,x); } } if(dp<d) rem[x]=1; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cin>>n>>d; h[1]=1; int max_h=1; for(int i=2;i<=n;i++) { int p; cin>>p; p++; h[i]=h[p]+1; vep[h[i]].push_back(i); max_h=max(max_h,h[i]); ma[p].push_back(i); ma[i].push_back(p); } int ans=0; for(int cur_h=max_h;cur_h>=0;cur_h--) { for(int v:vep[cur_h]) { if(!rem[v]) { ans++; remove(v); } } } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...