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 MAXN = 2e5;
template<class T> using matrix = vector<vector<T>>;
matrix<int> G;
int n, d, dist[20][20], par[MAXN + 5];
void dfs(int u, int p, int c, int d = 0){
dist[c][u] = d;
if(par[u] != p) dfs(par[u], u, c, d + 1);
for(auto v : G[u]){
if(v == p) continue;
dfs(v, u, c, d + 1);
}
}
int main(){
cin >> n >> d;
G = matrix<int>(n + 1);
for(int i = 2; i <= n; i ++){
cin >> par[i]; ++ par[i];
G[par[i]].push_back(i);
}
for(int u = 1; u <= n; u ++){
dfs(u, u, u);
}
int ans = 0;
for(int mask = 0; mask < (1 << n); mask ++){
bool bad = false;
for(int i = 0; i < n; i ++){
for(int j = 0; j < n; j ++){
if(i != j && dist[i + 1][j + 1] < d && ((mask >> i) & 1) && ((mask >> j) & 1)){
bad = true;
}
}
}
if(!bad){
ans = max(ans, __builtin_popcount(mask));
}
}
cout << ans << endl;
}
/*
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |