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;
const int mxn=5e3+5;
int n,ans[mxn],dis[mxn],sum;
vector<int>v[mxn];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
int k;
cin>>k;
for(int j=1;j<=k;j++){
int x;
cin>>x;
v[x].push_back(i);
}
}
int d=1e9;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)dis[j]=0;
sum=0;
dis[i]=1;
queue<int>q;
q.push(i);
while(q.size()){
int x=q.front();
ans[i]+=dis[x];
sum++;
q.pop();
for(auto j:v[x]){
if(dis[j]==0)dis[j]=dis[x]+1,q.push(j);
}
}
if(sum<n)ans[i]=1e9;
d=min(ans[i],d);
}
cout<<d<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |