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 ep emplace
#define epb emplace_back
#define int long long
using namespace std;
int n, va[5007], mn = LLONG_MAX, value;
vector<int> adj[5007];
bool visited[5007];
queue<pair<int,int>> q;
signed main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
int num;
cin >> num;
while (num--)
{
int v;
cin >> v;
adj[v].epb(i);
}
}
for (int i = 1; i <= n; i++)
{
q.push({1, i});
int sum = 0, cnt = 0;
memset(visited, 0, sizeof(visited));
while (!q.empty())
{
int u = q.front().second, cost = q.front().first;
q.pop();
if (visited[u])
continue;
visited[u] = true;
sum += cost;
cnt++;
for (auto v : adj[u])
if (!visited[v])
q.push({cost + 1, v});
}
if (cnt == n)
mn = min(mn, sum);
}
cout << mn;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |