Submission #1121365

#TimeUsernameProblemLanguageResultExecution timeMemory
1121365ezdpCat in a tree (BOI17_catinatree)C++14
11 / 100
93 ms596 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...