| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 865025 | maks007 | Cat in a tree (BOI17_catinatree) | C++14 | 1 ms | 344 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.
// 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 = 0;
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)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
