답안 #865025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865025 2023-10-24T02:43:32 Z maks007 Cat in a tree (BOI17_catinatree) C++14
0 / 100
1 ms 344 KB
// 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

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 ++) {
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -