| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 974481 | KasymK | Cat in a tree (BOI17_catinatree) | C++17 | 1052 ms | 3928 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.
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N], vis;
int n, d;
int mx = INT_MIN;
int marked[N], dis[N], vis1[N];
int poz = 0;
int in_yakyn(int x){
	queue <int> q;
	for (int i = 0; i < n; ++i) vis1[i] = dis[i] = 0;
	q.push(x);
	vis1[x] = 1;	
	while(!q.empty()){
		int to = q.front();
		q.pop();
		for (int i : adj[to])
			if (!vis1[i]){
                dis[i] = dis[to] + 1;
                q.push(i);
                vis1[i] = 1;
                if (vis[i])
                    return dis[i];
		    }
	}
}
bool barla(){
    int cnt = count(vis.begin(), vis.end(), 1);
    if(cnt <= 1)
        return 1;
   	for (int i = 0; i < n; ++i)
   		if(vis[i])
   			if(in_yakyn(i) < d)
                return 0; 	
	return 1;
}
int sana(){
	int ret = 0;
	for (int i = 0; i < n; ++i)
		ret += vis[i];
	return ret;
}
void f(int x){
    if(x == n){
        if(barla())
            mx = max(mx, sana());
        return;
    }
    for(int i = 0; i <= 1; ++i){
        vis[x] = i;
        f(x + 1);
    }
}
int main() { 
    scanf("%d%d", &n, &d);
    for(int i = 1; i <= n - 1; ++i) {
        int a;
        scanf("%d", &a);
        adj[a].push_back(i);
        adj[i].push_back(a);
    }
    vis.resize(n);
    f(0);
    printf("%d\n", mx);
    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... | ||||
