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;
#define maxn 5010
int n;
bool vis[maxn];
vector<vector<int>> ch(maxn);
queue<int> q;
int dep[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
int v;
for (int i = 1; i <= n; i++) {
int ct;
cin >> ct;
for (int j = 0; j < ct; j++) {
cin >> v;
ch[v].push_back(i);
}
}
int ans = n*n;
for (int i = 1; i <= n; i++) {
fill(vis, vis+maxn, false);
q.push(i);
dep[i] = 1;
vis[i] = true;
int cans = 1;
while (!q.empty()) {
v = q.front(); q.pop();
for (int vv : ch[v]) {
if (!vis[vv]) {
dep[vv] = dep[v]+1;
vis[vv] = true;
cans += dep[vv];
q.push(vv);
}
}
}
bool ok = true;
for (int j = 1; j <= n; j++) {
if (!vis[j]) {
ok = false;
// cout << "missed!" << endl;
}
}
if (ok) ans = min(ans, cans);
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |