# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1166906 | tch1cherin | Cat in a tree (BOI17_catinatree) | C++17 | 408 ms | 354736 KiB |
#include<bits/stdc++.h>
using namespace std;
int N,D,A,P,X[1<<19]{},i=1;
deque<int>G[1<<19];
main(){
for(cin>>N>>D;i<N;)cin>>P,G[P].push_back(i++);
for(A=i--;~i;--i)for(int j:G[i])
if(++X[j]+X[i]<D)X[i]=max(X[i],X[j]),--A;
else X[i]=min(X[i],X[j]);
cout<<A;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |