This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
vector <int> v[5001],child[5001];
int vis[5001];
int d[5001];
int n,k;
int bfs(int i){
for(int i=1;i<=n;i++) child[i].clear();
memset(vis,0,sizeof vis);
memset(d,0,sizeof d);
queue <int> qu;
qu.push(i);
d[i]=1;
vis[i]=1;
int tot=0;
while(!qu.empty()){
int I=qu.front();
tot+=vis[I];
qu.pop();
for(int j:v[I]){
if(vis[j]!=1){
child[I].push_back(j);
vis[j]=1;
d[j] = d[I]+1;
qu.push(j);
}
}
}
int sum=0;
for(int i=1;i<=n;i++) sum+=d[i];
if(tot!=n) return 1e18;
return sum;
}
signed main()
{
cin>>n;
for(int i=1;i<=n;i++){
cin>>k;
for(int j=1;j<=k;j++){
int a;
cin>>a;
v[a].push_back(i);
}
}
int mn=1e18;
for(int i=1;i<=n;i++) mn=min(bfs(i),mn);
cout<<mn;
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... |