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>
#define int long long
using namespace std;
signed main(){
int n;
cin >> n;
vector<int> adj[n + 1];
for(int i = 0; i < n; i++){
int x; cin >> x;
for(int j = 0; j < x; j++){
int a;
cin >> a;
adj[a].push_back(i + 1);
}
}
int mn = INT_MAX;
for(int i = 1; i <= n; i++){
vector<int> used(n + 1), d(n + 1, 1), p(n + 1);
queue<int> q;
q.push(i);
used[i] = 1;
p[i] = -1;
while(!q.empty()){
int v = q.front();
q.pop();
for(int u: adj[v]){
if(!used[u]){
used[u] = true;
q.push(u);
d[u] = d[v] + 1;
p[u] = v;
}
}
}
int sum = 0;
for(int i = 1; i <= n; i++){
sum += d[i];
}
for(int i = 1; i <= n; i++){
if(!used[i]) continue;
}
mn = min(sum, mn);
fill(used.begin(), used.end(), 0);
}
cout << mn;
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... |