제출 #974481

#제출 시각아이디문제언어결과실행 시간메모리
974481KasymKCat in a tree (BOI17_catinatree)C++17
11 / 100
1052 ms3928 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

catinatree.cpp: In function 'bool barla()':
catinatree.cpp:38:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   38 |     if(cnt <= 1)
      |     ^~
catinatree.cpp:40:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   40 |     for (int i = 0; i < n; ++i)
      |     ^~~
catinatree.cpp: In function 'int in_yakyn(int)':
catinatree.cpp:17:14: warning: control reaches end of non-void function [-Wreturn-type]
   17 |  queue <int> q;
      |              ^
catinatree.cpp: In function 'int main()':
catinatree.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     scanf("%d%d", &n, &d);
      |     ~~~~~^~~~~~~~~~~~~~~~
catinatree.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...