제출 #1115989

#제출 시각아이디문제언어결과실행 시간메모리
1115989vjudge1Cat in a tree (BOI17_catinatree)C++17
100 / 100
118 ms35668 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define int long long int d; const int MAXN=2*1e5; vector<vector<int>> graph(MAXN); vector<multiset<int>> choose(MAXN); int depth[MAXN]; void DFS(int u){ choose[u].insert(depth[u]); for(int v:graph[u]){ depth[v]=depth[u]+1; DFS(v); if(choose[u].size()<choose[v].size()){ swap(choose[u],choose[v]); } while(choose[v].size()>0){ int x=*(choose[v].begin()); choose[u].insert(x); choose[v].erase(choose[v].begin()); } } while(choose[u].size()>1){ multiset<int>::iterator it1=choose[u].begin(); multiset<int>::iterator it2=it1; it2++; if((*it1)+(*it2)-2*depth[u]<d){ choose[u].erase(choose[u].begin()); } else{ break; } } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n >> d; for(int i=1;i<n;i++){ int p; cin >> p; graph[p].push_back(i); } DFS(0); cout << choose[0].size() << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...