# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30720 | 2017-07-26T09:06:15 Z | RayaBurong25_1 | Bosses (BOI16_bosses) | C++14 | 0 ms | 1308 KB |
#include <stdio.h> #include <vector> #define INF 1000000000000000000LL std::vector<int> AdjList[5005]; long long min(long long a, long long b) { return (a < b)?a:b; } int Vis[5005]; int cnt, sz; long long sum; long long DFS(int u, int pa) { // printf("DFS %d %d\n", u, pa); Vis[u] = cnt; sz++; int i, v, s = AdjList[u].size(); long long r = 0; for (i = 0; i < s; i++) { v = AdjList[u][i]; if (Vis[v] < cnt) { r += DFS(v, u); } } r++; sum += r; return r; } int main() { int N; 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); } } long long Ans = INF; long long r; for (i = 1; i <= N; i++) { // printf("Root %d\n", i); cnt++; sz = 0; sum = 0; DFS(i, 0); // printf("%lld\n", sum); if (sz == N) Ans = min(Ans, sum); } printf("%lld", Ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 1308 KB | Output is correct |
2 | Incorrect | 0 ms | 1308 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 1308 KB | Output is correct |
2 | Incorrect | 0 ms | 1308 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 1308 KB | Output is correct |
2 | Incorrect | 0 ms | 1308 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |