제출 #24438

#제출 시각아이디문제언어결과실행 시간메모리
24438BruteforcemanBosses (BOI16_bosses)C++11
100 / 100
656 ms2292 KiB
#include "bits/stdc++.h"
using namespace std;

vector <int> g[5005];
int d[5005];
int n;

int query(int root) {
	memset(d, -1, sizeof d);
	queue <int> Q;
	Q.push(root);
	d[root] = 1;
	while(!Q.empty()) {
		int x = Q.front();
		Q.pop();

		for(auto i : g[x]) {
			if(d[i] == -1) {
				d[i] = 1 + d[x];
				Q.push(i);
			}
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(d[i] == -1) return -1;
		else ans += d[i];
	}
	return ans;
}

int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		int p;
		scanf("%d", &p);
		for(int j = 1; j <= p; j++) {
			int x;
			scanf("%d", &x);
			g[x].push_back(i);
		}
	}
	int ans = INT_MAX;
	for(int i = 1; i <= n; i++) {
		int x = query(i);
		if(x == -1) continue;
		ans = min(ans, x);
	}
	printf("%d\n", ans);
	return 0;
}

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

bosses.cpp: In function 'int main(int, const char**)':
bosses.cpp:34:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
bosses.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &p);
                  ^
bosses.cpp:40:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &x);
                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...