답안 #58207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58207 2018-07-17T07:20:19 Z PeppaPig Bosses (BOI16_bosses) C++14
67 / 100
1500 ms 1352 KB
#include <bits/stdc++.h>

#define pii pair<int, int>
#define x first
#define y second

using namespace std;

const int N = 5e3 + 5;

int n, ans = INT_MAX;
vector<vector<int> > g(N);
int sal[N], par[N], dep[N];
bool vis[N];

int bfs(int root) {
	int ret = 0;
	queue<int> Q;
	stack<int> S;
	memset(vis, false, sizeof vis);
	for(int i = 1; i <= n; i++) sal[i] = 1, dep[i] = INT_MAX;

	Q.emplace(root);
	par[root] = 0;
	dep[root] = 1;
	vis[root] = true;

	while(!Q.empty()) {
		int now = Q.front();
		Q.pop();

		S.emplace(now);
		for(int v : g[now]) if(dep[now] + 1 < dep[v] && !vis[v]) {
			vis[v] = true;
			dep[v] = dep[now] + 1;
			par[v] = now;
			Q.emplace(v);
		} 
	}

	vector<pii> proc;
	for(int i = 1; i <= n; i++) {
		if(dep[i] == INT_MAX) return INT_MAX;
		proc.emplace_back(dep[i], i);
	}
	sort(proc.begin(), proc.end(), [&](const pii &a, const pii &b) {
		return a.x > b.x;
	});
	for(pii v : proc) sal[par[v.y]] += sal[v.y];
	for(int i = 1; i <= n; i++) ret += sal[i];
	return ret;
}

int main() {
	scanf("%d", &n);
	for(int i = 1, k; i <= n; i++) {
		scanf("%d", &k);
		while(k--) {
			int v;
			scanf("%d", &v);
			g[v].emplace_back(i);
		}
	} 

	for(int i = 1; i <= n; i++) ans = min(ans, bfs(i));
	printf("%d", ans);

	return 0;
}

Compilation message

bosses.cpp: In function 'int main()':
bosses.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
bosses.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &k);
   ~~~~~^~~~~~~~~~
bosses.cpp:60:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &v);
    ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 3 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 3 ms 612 KB Output is correct
7 Correct 3 ms 672 KB Output is correct
8 Correct 3 ms 672 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 4 ms 748 KB Output is correct
11 Correct 5 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 3 ms 612 KB Output is correct
7 Correct 3 ms 672 KB Output is correct
8 Correct 3 ms 672 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 4 ms 748 KB Output is correct
11 Correct 5 ms 748 KB Output is correct
12 Correct 14 ms 748 KB Output is correct
13 Correct 8 ms 748 KB Output is correct
14 Correct 215 ms 876 KB Output is correct
15 Correct 47 ms 1000 KB Output is correct
16 Correct 894 ms 1000 KB Output is correct
17 Execution timed out 1564 ms 1352 KB Time limit exceeded
18 Halted 0 ms 0 KB -