This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |