# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30721 | 2017-07-26T09:15:05 Z | RayaBurong25_1 | Bosses (BOI16_bosses) | C++14 | 723 ms | 2224 KB |
#include <stdio.h> #include <vector> #include <queue> #define INF 1000000000 std::vector<int> AdjList[5005]; int min(int a, int b) { return (a < b)?a:b; } int Vis[5005]; int cnt, sz; int sum; std::queue<int> Q; int H[5005]; int N; void BFS(int u) { // printf("DFS %d %d\n", u, pa); int i; for (i = 1; i <= N; i++) H[i] = INF; Q.push(u); H[u] = 1; sum += H[u]; sz++; int p; int v, s; while (!Q.empty()) { p = Q.front(); Q.pop(); s = AdjList[p].size(); for (i = 0; i < s; i++) { v = AdjList[p][i]; if (H[v] == INF) { Q.push(v); H[v] = H[p] + 1; sum += H[v]; sz++; } } } } int main() { scanf("%d", &N); int i, j, K; int p; for (i = 1; i <= N; i++) { scanf("%d", &K); for (j = 0; j < K; j++) { scanf("%d", &p); AdjList[p].push_back(i); } } int Ans = INF; // int r; for (i = 1; i <= N; i++) { // printf("Root %d\n", i); cnt++; sz = 0; sum = 0; BFS(i); // printf("%lld\n", sum); if (sz == N) Ans = min(Ans, sum); } printf("%d", Ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2092 KB | Output is correct |
2 | Correct | 0 ms | 2092 KB | Output is correct |
3 | Correct | 0 ms | 2092 KB | Output is correct |
4 | Correct | 0 ms | 2092 KB | Output is correct |
5 | Correct | 0 ms | 2092 KB | Output is correct |
6 | Correct | 0 ms | 2092 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2092 KB | Output is correct |
2 | Correct | 0 ms | 2092 KB | Output is correct |
3 | Correct | 0 ms | 2092 KB | Output is correct |
4 | Correct | 0 ms | 2092 KB | Output is correct |
5 | Correct | 0 ms | 2092 KB | Output is correct |
6 | Correct | 0 ms | 2092 KB | Output is correct |
7 | Correct | 0 ms | 2092 KB | Output is correct |
8 | Correct | 0 ms | 2092 KB | Output is correct |
9 | Correct | 0 ms | 2092 KB | Output is correct |
10 | Correct | 0 ms | 2092 KB | Output is correct |
11 | Correct | 0 ms | 2092 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2092 KB | Output is correct |
2 | Correct | 0 ms | 2092 KB | Output is correct |
3 | Correct | 0 ms | 2092 KB | Output is correct |
4 | Correct | 0 ms | 2092 KB | Output is correct |
5 | Correct | 0 ms | 2092 KB | Output is correct |
6 | Correct | 0 ms | 2092 KB | Output is correct |
7 | Correct | 0 ms | 2092 KB | Output is correct |
8 | Correct | 0 ms | 2092 KB | Output is correct |
9 | Correct | 0 ms | 2092 KB | Output is correct |
10 | Correct | 0 ms | 2092 KB | Output is correct |
11 | Correct | 0 ms | 2092 KB | Output is correct |
12 | Correct | 6 ms | 2224 KB | Output is correct |
13 | Correct | 3 ms | 2224 KB | Output is correct |
14 | Correct | 173 ms | 2224 KB | Output is correct |
15 | Correct | 13 ms | 2224 KB | Output is correct |
16 | Correct | 696 ms | 2224 KB | Output is correct |
17 | Correct | 723 ms | 2224 KB | Output is correct |
18 | Correct | 719 ms | 2224 KB | Output is correct |