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);
int n;
cin >> n;
vector<vector<int>> adj(n, vector<int>());
for (int i = 0; i < n; i++) {
int k;
cin >> k;
while (k--) {
int p;
cin >> p;
adj[--p].push_back(i);
}
}
int res = 1e9;
for (int r = 0; r < n; r++) {
vector<int> d(n, -1);
queue<int> qu;
d[r] = 1;
qu.push(r);
while (!qu.empty()) {
int u = qu.front();
qu.pop();
for (int v : adj[u])
if (d[v] == -1) {
d[v] = d[u] + 1;
qu.push(v);
}
}
if (*min_element(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... |