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>> g (n+1);
for (int i = 1; i < n+1; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int x;
cin >> x;
g[x].push_back(i);
}
}
int mini = 1000000000;
for (int i = 1; i < n+1; i++) {
vector<bool> odw (n+1, 0);
vector<int> d (n+1, 0);
odw[i] = 1;
d[i] = 1;
queue<int> q;
q.push(i);
int score = 1;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : g[v]) {
if (!odw[u]) {
odw[u] = 1;
d[u] = d[v]+1;
score += d[u];
q.push(u);
}
}
}
for (int i = 1; i < n+1; i++) {
if (!odw[i]) {
score = 1000000000;
}
}
mini = min(mini, score);
}
cout << mini << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |