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 pii pair<int,int>
#define f first
#define s second
#define ll long long
vector<int> g[5555];
int vis[5555];
queue<pii> qu;
int main()
{
cin.tie()->sync_with_stdio(0);
int n;cin>>n;
for(int i=1;i<=n;i++)
{
int m;cin>>m;
for(int j=1;j<=m;j++)
{
int k;cin>>k;
g[k].push_back(i);
}
}
ll ans=1e18;
for(int i=1;i<=n;i++)
{
memset(vis,0,sizeof vis);
qu.push({i,1});ll cnt=1;
int ch=1;
vis[i]=1;
//cout<<'\n'<<i<<'\n';
while(!qu.empty())
{
pii now=qu.front();
qu.pop();
for(auto x:g[now.f])
{
if(vis[x]) continue;
vis[x]=1;
ch++;
//cout<<now.f<<' '<<x<<'\n';
qu.push({x,now.s+1});
cnt+=now.s+1;
//cout<<cnt<<'\n';
}
}
if(ch<n) continue;
ans=min(cnt,ans);
// cout<<ans<<' '<<i<<'\n';
}
cout<<ans;
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... |