제출 #974506

#제출 시각아이디문제언어결과실행 시간메모리
974506KasymKCat in a tree (BOI17_catinatree)C++17
11 / 100
1031 ms3788 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], see[N];

int in_yakyn(int x){
	for (int i = 0; i < n; ++i)
        see[i] = dis[i] = 0;
	queue<int> q;
    q.push(x);
	see[x] = 1;	
	while(!q.empty()){
		int id = q.front();
		q.pop();
		for (int i : adj[id])
			if (!see[i]){
                dis[i] = dis[id] + 1;
                see[i] = 1;
                if(vis[i])
                    return dis[i];
                q.push(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] and in_yakyn(i) < d)
            return 0; 	
	return 1;
}

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