# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79526 | IOrtroiii | Bosses (BOI16_bosses) | C++14 | 666 ms | 888 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n;
vector<int> g[N];
int F[N];
long long bfs(int root) {
for (int i = 1; i <= n; ++i) F[i] = 0;
long long sum = 0;
int cnt = 0;
queue<int> q; q.push(root);
F[root] = 1;
while (!q.empty()) {
int u = q.front(); q.pop();
sum += F[u]; cnt++;
for (int v : g[u]) if (F[v] == 0) {
F[v] = F[u] + 1;
q.push(v);
}
}
if (cnt < n) return 1e18;
return sum;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int x; scanf("%d", &x);
while (x--) {
int u; scanf("%d", &u);
g[u].push_back(i);
}
}
long long res = 1e18;
for (int i = 1; i <= n; ++i) res = min(res, bfs(i));
cout << res << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |