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, vis[5050], k, u, ans = 1e9;
vector<int> vc[5050];
queue<pair<int, int>> q;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n;
for(int i = 1; i<=n; ++i){
cin >> k;
while(k--){
cin >> u;
vc[u].emplace_back(i);
}
}
for(int i = 1; i<=n; ++i){
int sum = 0, node = 0;
memset(vis, 0, sizeof(vis));
q.emplace(i, 1);
while(!q.empty()){
int u = q.front().first, w = q.front().second; q.pop();
if(vis[u]) continue;
vis[u] = 1;
++node;
sum+=w;
for(auto v:vc[u]) if(!vis[v]) q.emplace(v, w+1);
}
//cout << node << ' ' << sum << '\n';
if(node == n) ans = min(ans, sum);
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |