#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef JahonaliX
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, z = INT_MAX;
cin >> n;
vector<vector<int>> a(n);
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
while (k--) {
int x;
cin >> x;
x--;
a[x].emplace_back(i);
}
}
for (int i = 0; i < n; ++i) {
vector<bool> v(n);
v[i] = true;
queue<int> q;
q.emplace(i);
vector<int> d(n, 1);
while (!q.empty()) {
int x = q.front();
q.pop();
for (int j : a[x]) {
if (v[j]) continue;
d[j] = d[x] + 1;
q.emplace(j);
v[j] = true;
}
}
bool ok = true;
for (int j = 0; j < n; ++j) ok &= v[j];
if (ok) z = min(z, accumulate(d.begin(), d.end(), 0));
}
cout << z;
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... |