# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136209 | thebes | Cat in a tree (BOI17_catinatree) | C++14 | 116 ms | 18008 KiB |
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;
const int MN = 2e5+5;
int N, D, i, x, d[MN], ans;
vector<int> adj[MN];
void solve(int n){
vector<int> vec;
for(auto v : adj[n]){
solve(v);
vec.push_back(d[v]-1);
}
sort(vec.begin(),vec.end(),[](int i,int j){return i>j;});
while(vec.size()>=2){
if(vec[0]+vec[1]<=D) break;
else{
ans--;
vec.erase(vec.begin());
}
}
if(vec.empty()||vec[0]<=0){
ans ++;
d[n] = D;
}
else d[n] = vec[0];
}
int main(){
for(scanf("%d%d",&N,&D),i=2;i<=N;i++){
scanf("%d",&x);
adj[x+1].push_back(i);
}
solve(1);
printf("%d\n",ans);
return 0;
}
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... |