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>
//#include "game.h"
using namespace std;
vector<int> v[5001];
long long all = 0;
int main(){
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
for(int i = 1;i<=n;i++){
int k;
cin>>k;
for(int j = 0;j<k;j++){
int x;cin>>x;
v[x].push_back(i);
}
}
long long ans = 1e18;
for(int i = 1;i<=n;i++){
all = 1;
int vis[n+1] = {0};
vis[i] = 1;
queue<int> q;q.push(i);
int cnt = 0;
while(!q.empty()){
int w = q.front();q.pop();
cnt++;
for(auto j:v[w]){
if(vis[j]==0){
vis[j] = vis[w]+1;
all += vis[j];
q.push(j);
}
}
}
if(cnt==n){
ans = min(ans,all);
}
}
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |