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>
#pragma GCC optimize("unroll-loops")
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 200005
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
int d[N];
vector<int> adj[N];
vector<int> v;
void dfs(int v, int p){
d[v] = d[p] + 1;
for(int& x : adj[v]){
if(x == p) continue;
dfs(x, v);
}
}
void dfs2(int v, int t){
d[v] = -t;
if(t == 1) return;
t--;
for(int& x : adj[v]){
if(d[x] > -t){
dfs2(x, t);
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, t;
cin>>n>>t;
for(int i = 1; i < n; i++){
int v, u;
cin>>u;
++u;
v = i + 1;
adj[v].push_back(u);
adj[u].push_back(v);
::v.push_back(i);
}
::v.push_back(n);
dfs(1, 0);
sort(v.begin(), v.end(),[](const int& lhs, const int& rhs){
return d[lhs] > d[rhs];
});
int ans = 0;
for(int& a : v){
if(d[a] > 0){
ans++;
dfs2(a, t);
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |