# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
532592 | GioChkhaidze | Bosses (BOI16_bosses) | C++17 | 790 ms | 700 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
#define pb push_back
using namespace std;
const int N = 5005;
vector < ll > g[N];
ll res, ans = 1e18, dep[N];
main () {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
ll n;
cin >> n;
for (int i = 1; i <= n; ++i) {
ll sz;
cin >> sz;
for (int j = 1; j <= sz; ++j) {
ll x;
cin >> x;
g[x].pb(i);
}
}
queue < ll > q;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
dep[j] = 0;
}
res = 0;
q.push(i);
dep[i] = 1;
while (q.size()) {
int x = q.front();
q.pop();
res += dep[x];
for (int j = 0; j < g[x].size(); ++j) {
int to = g[x][j];
if (!dep[to]) {
dep[to] = dep[x] + 1;
q.push(to);
}
}
}
bool bo = false;
for (int j = 1; j <= n; ++j) {
if (!dep[j]) bo = true;
}
if (!bo) {
ans = min(ans, res);
}
res = 0;
}
assert(ans != 1e18);
cout << ans << "\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... |