# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
657175 | quocnguyen1012 | Bosses (BOI16_bosses) | C++14 | 626 ms | 664 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;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("input.txt", "r")) freopen("input.txt", "r", stdin);
int n; cin >> n;
vector<vector<int>> adj(n + 5);
for (int i = 1; i <= n; ++i) {
int k; cin >> k;
while (k--) {
int v; cin >> v;
// adj[i].emplace_back(v);
adj[v].emplace_back(i);
}
}
vector<int> d(n + 5, -1);
int ans = INT_MAX;
for (int r = 1; r <= n; ++r) {
queue<int> Q;
fill(d.begin(), d.end(), -1);
int tot = 0;
for (d[r] = 1, Q.push(r); !Q.empty(); ) {
int u = Q.front(); Q.pop();
for (int v : adj[u]) {
if (d[v] == -1) {
d[v] = d[u] + 1;
Q.push(v);
}
}
}
bool bad = false;
for (int i = 1; i <= n; ++i) {
tot += d[i];
if (d[i] == -1) bad = true;
}
if (not bad)
ans = min(ans, tot);
}
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... |