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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
vector<vector<int>> g(n);
for (int i = 0; i < n; ++i) {
int k; cin >> k;
while (k--) {
int j; cin >> j; --j;
g[j].push_back(i);
}
}
vector<int> d(n, -1);
int res = 1e9;
for (int r = 0; r < n; ++r) {
fill(d.begin(), d.end(), -1);
d[r] = 1;
queue<int> q{{r}};
while (q.size()) {
int u = q.front(); q.pop();
for (int v : g[u]) {
if (d[v] == -1) {
d[v] = d[u] + 1;
q.push(v);
}
}
}
if (!count(d.begin(), d.end(), -1)) {
res = min(res, accumulate(d.begin(), d.end(), 0));
}
}
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |