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 pb push_back
int n,x,u,v,ans=1e9;
vector <int> edge[5007];
int vis[5007];
void go(int root){
queue <int> q;
q.push(root);
vis[root]=1;
int ret=0;
while(!q.empty()){
int u=q.front();
q.pop();
ret+=vis[u];
for(int v:edge[u]){
if(!vis[v]){
vis[v]=vis[u]+1;
q.push(v);
}
}
}
ans=min(ans,ret);
}
int main(){
ios_base::sync_with_stdio(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>x;
while(x>0){
x--;
cin>>v;
edge[v].pb(i);
}
}
for(int i=1;i<=n;i++){
memset(vis,0,sizeof(vis));
go(i);
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |