This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Bismi ALlah
#include "bits/stdc++.h"
using namespace std;
signed main () {
int n, d;
cin >> n >> d;
vector <int> g[n];
function <int(int,int,int, int)> get=[&](int v, const int & target, int p, int dist) {
if(target == v) return dist;
int f = -1;
for(auto u : g[v]) {
if(u == p) continue;
f = max(f, get(u, target, v, dist + 1));
}
return f;
};
for(int i = 1; i < n; i ++) {
int p;
cin >> p;
g[i].push_back(p);
g[p].push_back(i);
}
int ans = 1;
for(int mask = 0; mask < (1 << n); mask ++) {
vector <int> v;
for(int i= 0; i < n; i ++) {
if(mask & (1 << i)) v.push_back(i);
}
for(int i = 1; i < v.size(); i ++) {
if(get(v[i-1], v[i], -1, 0) >= d) continue;
goto end;
}
// cout << mask << " ";
ans = max(ans, __builtin_popcount(mask));
end:;
}
cout << ans;
return 0;
}
Compilation message (stderr)
catinatree.cpp: In function 'int main()':
catinatree.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 1; i < v.size(); i ++) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |