# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1039043 | Hanksburger | Cat in a tree (BOI17_catinatree) | C++17 | 36 ms | 21844 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;
a.push_back(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()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
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... |