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 n,k,pom;
vector<int> mat[5003];
int dist[5003];
queue<int> q;
long long cnt[5003],res;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> k;
for(int j = 0; j < k; j++){
cin >> pom;
mat[pom].push_back(i);
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++)
dist[j] = 9999999;
dist[i] = 1;
q.push(i);
while(!q.empty()){
pom = q.front();
q.pop();
for(auto x: mat[pom]){
if(dist[x] != 9999999)
continue;
dist[x] = dist[pom] + 1;
q.push(x);
}
}
for(int j = 1; j <= n; j++){
cnt[i] += dist[j];
}
}
res = cnt[1];
for(int i = 2; i <= n; i++){
res = min(res,cnt[i]);
}
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |