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;
const int N = 5010;
vector <int> g[N];
int mark[N];
int main(){
int n;
cin >> n;
for(int i = 1;i <= n;i++){
int x;
cin >> x;
for(int j = 0;j < x;j++){
int t;
cin >> t;
g[t].push_back(i);
}
}
int res = 1e9;
for(int v = 1;v <= n;v++){
for(int i = 1;i <= n;i++){
mark[i] = 0;
}
queue <int> q;
mark[v] = 1;
q.push(v);
int sum = 0;
while(!q.empty()){
int t = q.front();
q.pop();
sum += mark[t];
for(auto x : g[t]){
if(mark[x] > 0) continue;
mark[x] = mark[t]+1;
q.push(x);
}
}
bool aux = true;
for(int i = 1;i <= n;i++){
if(mark[i] == 0) aux = false;
}
if(aux) res = min(res, sum);
}
cout << res << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |