This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Failure will never overtake me if my determination to succeed is strong enough
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a[n];
for(int i = 0; i < n; i++)
{
int m;
cin >> m;
while(m--)
{
int x;
cin >> x;
a[x-1].push_back(i);
}
}
long long rez = INT_MAX;
for(int i = 0; i < n; i++)
{
int vis[n];
for(int j = 0; j < n; j++)
vis[j] = -1;
queue<int> q;
q.push(i);
vis[i] = 1;
while(!q.empty())
{
int x = q.front();
q.pop();
for(auto j: a[x])
{
if(vis[j] == -1)
{
vis[j] = vis[x]+1;
q.push(j);
}
}
}
bool moze = true;
map<int, int> nivoi;
for(int j = 0; j < n; j++)
{
if(vis[j] == -1)
moze = false;
nivoi[vis[j]]++;
}
if(!moze)
continue;
long long tmpr = 0;
for(auto j: nivoi)
{
tmpr += j.first*j.second;
}
rez = min(rez, tmpr);
}
cout << rez;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |