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>
#define int long long int
#define ff first
#define ss second
#define FT ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int n;
const int maxn = 2e3 + 10;
const int inf = 1e15;
vector <int> adj[maxn];
bool mark[maxn];
int h[maxn];
queue <int> q;
int bfs (int r)
{
for (int i = 1 ; i <= n ; i++)
{
h[i] = inf;
}
h[r] = 1;
q.push(r);
mark[r] = true;
while (!q.empty())
{
int v = q.front();
q.pop();
for (auto u : adj[v])
{
if (!mark[u])
{
h[u] = h[v] + 1;
q.push(u);
mark[u] = true;
}
}
}
int sum = 0;
for (int i = 1 ; i <= n ; i++)
{
sum += h[i];
mark[i] = false;
}
return sum;
}
signed main()
{
FT;
cin >> n;
for (int i = 1 ; i <= n ; i++)
{
int k;
cin >> k;
while (k--)
{
int b;
cin >> b;
adj[b].push_back(i);
}
}
int ans = 1e15;
for (int i = 1 ; i <= n ; i++)
{
ans = min (ans , bfs(i));
}
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... |