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;
int main() {
int N;
cin>>N;
vector<int> e[10000];
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);
}
}
int cnt[N];
for(int i=0; i<N; i++) {
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;
q.push(j);
}
}
}
int sum=0;
for(int j=0; j<N; j++){
// cout<<d[j]<<" ";
sum+=d[j];
}
cnt[i]=sum;
// cout<<cnt[i]<<endl;
}
sort(cnt,cnt+N);
cout<<cnt[0]<<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... |