# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1039044 | Hanksburger | Cat in a tree (BOI17_catinatree) | C++17 | 58 ms | 20584 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;
vector<int>j[200005];
int n,d,s,x;
int f(int u)
{
s++;
vector<int>a(1,0);
for (int v:j[u])
a.push_back(f(v)+1);
sort(a.begin(),a.end());
int m=0;
while (m+1<a.size()&&a[m]+a[m+1]<d)
m++,s--;
return a[m];
}
int main()
{
cin>>n>>d;
for(int i=1;i<n;i++)
cin>>x,j[x].push_back(i);
f(0);
cout<<s;
}
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... |