Submission #963670

#TimeUsernameProblemLanguageResultExecution timeMemory
963670pccCat in a tree (BOI17_catinatree)C++17
100 / 100
31 ms15700 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const int mxn = 2e5+10; int N,D; vector<int> tree[mxn]; pii dp[mxn]; void dfs(int now){ dp[now] = pii(1,0); for(auto nxt:tree[now]){ dfs(nxt); dp[now].fs += dp[nxt].fs; if(dp[now].sc+dp[nxt].sc+1<D){ dp[now].fs--; dp[now].sc = max(dp[now].sc,dp[nxt].sc+1); } else{ dp[now].sc = min(dp[now].sc,dp[nxt].sc+1); } } return; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N>>D; for(int i = 1;i<N;i++){ int p; cin>>p; tree[p].push_back(i); } dfs(0); cout<<dp[0].fs; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...