제출 #726964

#제출 시각아이디문제언어결과실행 시간메모리
726964groguCat in a tree (BOI17_catinatree)C++14
100 / 100
162 ms29224 KiB
#define here cerr<<"===========================================\n" #define dbg(x) cerr<<#x<<": "<<x<<endl; #include <bits/stdc++.h> #define ld double #define ll long long #define ull unsigned long long #define llinf 100000000000000000LL // 10^17 #define iinf 2000000000 // 2*10^9 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pii pair<int,int> #define pll pair<ll,ll> #define pld pair<ld,ld> #define all(a) a.begin(),a.end() using namespace std; #define maxn 200005 ll n,d; vector<ll> g[maxn]; pll dfs(ll u,ll p){ vector<ll> v; v.pb(0); ll cnt = 1; for(ll s : g[u]){ if(s==p) continue; pll cur = dfs(s,u); v.pb(cur.sc); cnt+=cur.fi; } sort(all(v)); reverse(all(v)); while(v.size()>1&&v[v.size()-1] + v[v.size()-2]<d){ v.popb(); cnt--; } return {cnt,v.back()+1}; } void tc(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); cin >> n >> d; for(ll i = 2;i<=n;i++){ ll x; cin >> x; x++; g[x].pb(i); g[i].pb(x); } pll ans = dfs(1,1); cout<<ans.fi<<endl; } int main(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); int t; t = 1; while(t--){ tc(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...