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>
typedef long long ll;
using namespace std;
const int inf = 1e9 + 5;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vector<int> > g(n);
for (int i = 0; i < n; i++)
{
int d; cin >> d;
for (int j = 0, x; j < d; j++)
{
cin >> x;
g[--x].push_back(i);
}
}
int ans = inf;
for (int i = 0; i < n; i++)
{
queue<int> q; q.push(i);
vector<int> d(n, inf); d[i] = 1;
while (!q.empty())
{
int u = q.front(); q.pop();
for (int v : g[u]) if (d[v] == inf) d[v] = d[u]+1, q.push(v);
}
int sum = 0;
for (int j = 0; j < n; j++) sum += d[j];
ans = min(ans, sum);
}
cout << ans << "\n";
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... |