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;
vector<int> e[100000];
int main() {
int N, ans = 0;
cin>>N;
for(int i=0; i<N; i++) {
int k;
cin>>k;
for(int j=0; j<k; j++) {
int a;
cin>>a;
a--;
e[a].push_back(i);
}
}
for(int i=0; i<N; i++) {
int sum = 1;
vector<int> d(N);
queue<int> q;
q.push(i);
d[i]=1;
while(!q.empty()) {
int u=q.front();
q.pop();
for(int j : e[u]) {
if(!d[j]) {
d[j]=d[u] + 1;
sum += d[j];
//cout<<sum<<" "<<d[j]<<endl;
q.push(j);
}
}
}
if(i==0){
ans = sum;
}else{
ans = min(sum,ans);
}
}
cout<<ans<<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... |