제출 #81547

#제출 시각아이디문제언어결과실행 시간메모리
81547arman_ferdousBosses (BOI16_bosses)C++17
100 / 100
625 ms1292 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 5010;
int n;
vector<int> g[N];

int d[N];
int bfs(int u) {
	queue<int> q; q.push(u);
	memset(d,-1,sizeof d); d[u] = 1;
	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(int v : g[u]) if(d[v] == -1) {
			d[v] = d[u] + 1;
			q.push(v);
		}
	} int ret = 0;
	for(int i = 1; i <= n; i++) {
		if(d[i] == -1) return (int)2e9;
		ret += d[i];
	} return ret;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		int sz, j; scanf("%d", &sz);
		while(sz--) {
			scanf("%d", &j);
			g[j].push_back(i);
		}
	}
	int ans = (int)2e9;
	for(int i = 1; i <= n; i++)
		ans = min(ans, bfs(i));	
	printf("%d\n", ans);
	return 0;
}

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

bosses.cpp: In function 'int main()':
bosses.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
bosses.cpp:28:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int sz, j; scanf("%d", &sz);
              ~~~~~^~~~~~~~~~~
bosses.cpp:30:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &j);
    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...