Submission #727994

# Submission time Handle Problem Language Result Execution time Memory
727994 2023-04-21T18:44:30 Z WonderfulWhale Bosses (BOI16_bosses) C++17
100 / 100
646 ms 708 KB
#include<bits/stdc++.h>
using namespace std;

#define int int64_t
#define pb push_back
#define st first
#define nd second
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

vector<int> G[5009];
bool vis[5009];
int d[5009];
int sum;
int cnt;

void bfs(int x) {
	queue<int> Q;
	Q.push(x);
	sum = cnt = 0;
	d[x] = 1;
	memset(vis, 0, sizeof(vis));
	vis[x] = true;
	while(sz(Q)) {
		int y = Q.front();
		Q.pop();
		cnt++;
		sum += d[y];
		for(int z:G[y]) {
			if(!vis[z]) {
				d[z] = d[y]+1;
				vis[z] = true;
				Q.push(z);
			}
		}
	}
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	for(int i=1;i<=n;i++) {
		int k;
		cin >> k;
		for(int j=0;j<k;j++) {
			int x;
			cin >> x;
			G[x].pb(i);
		}
	}
	int res = 1e18;
	for(int i=1;i<=n;i++) {
		bfs(i);
		if(cnt==n) res = min(res, sum);
	}
	cout << res << "\n";
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 114 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 491 ms 708 KB Output is correct
17 Correct 646 ms 696 KB Output is correct
18 Correct 639 ms 692 KB Output is correct