Submission #855199

# Submission time Handle Problem Language Result Execution time Memory
855199 2023-09-30T15:41:13 Z NK_ Bosses (BOI16_bosses) C++17
100 / 100
471 ms 852 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define pb push_back
#define pf push_front
 
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
 
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
 
using db = long double;
 
template<class T> using pq = priority_queue<T, V<T>, greater<T>>;
 
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 18;

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int N; cin >> N;
	V<vi> adj(N); for(int i = 0; i < N; i++) {
		int k; cin >> k;
		while(k--) {
			int x; cin >> x; --x;
			adj[x].pb(i);
		}
	}

	auto bfs = [&](int r) {

		vi dst(N, MOD), vis(N); dst[r] = 0;
		queue<int> q; q.push(r);

		while(sz(q)) {
			int u = q.front(); q.pop();

			if (vis[u]) continue;
			vis[u] = 1;

			for(auto& v : adj[u]) {
				if (dst[v] > dst[u]+1) {
					dst[v] = dst[u] + 1;
					q.push(v);
				}
			}
		}

		int ans = 0;
		for(int u = 0; u < N; u++) {
			ans += dst[u] + 1;
			ans = min(ans, MOD);
		}

		return ans;
	};

	int ans = MOD;
	for(int i = 0; i < N; i++) ans = min(ans, bfs(i));
	cout << ans << nl;

	exit(0-0);
} 	 
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 122 ms 604 KB Output is correct
15 Correct 51 ms 712 KB Output is correct
16 Correct 469 ms 600 KB Output is correct
17 Correct 468 ms 852 KB Output is correct
18 Correct 471 ms 808 KB Output is correct