# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79887 | Just_Solve_The_Problem | Bosses (BOI16_bosses) | C++11 | 672 ms | 1308 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>
#define ll long long
using namespace std;
const int N = (int)5e3 + 7;
const int inf = (int)1e9 + 7;
int n;
ll ans = 1e18;
vector < int > gr[N];
int d[N];
long long solve(int v) {
ll sum = n;
queue < int > q;
for (int i = 1; i <= n; i++) {
d[i] = inf;
}
d[v] = 0;
q.push(v);
while (!q.empty()) {
v = q.front();
q.pop();
for (int to : gr[v]) {
if (d[to] == inf) {
d[to] = d[v] + 1;
q.push(to);
}
}
}
for (int i = 1; i <= n; i++) {
sum += d[i];
if (d[i] == inf) {
return inf;
}
}
return sum;
}
main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int k;
scanf("%d", &k);
for (int j = 0; j < k; j++) {
int as;
scanf("%d", &as);
gr[as].push_back(i);
}
}
for (int i = 1; i <= n; i++) {
ans = min(ans, solve(i));
}
cout << ans;
}
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... |