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;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll linf = 123456789012345678;
const ll mod = 1000000007;
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
int n;
vvi c;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
c = vvi(n);
for(int i = 0; i < n; i++){
int k;
cin >> k;
for(int j = 0; j < k; j++){
int t;
cin >> t;
c[t-1].push_back(i);
}
}
int ans = inf;
for(int i = 0; i < n; i++){
int t_ans = 0;
vi seen(n);
seen[i] = true;
int sc = 1;
queue<pi> q;
q.push({i,1});
while(!q.empty()){
int e = q.front().first;
int d = q.front().second;
q.pop();
for(int x : c[e]){
if(seen[x]) continue;
seen[x] = 1;
q.push({x, d+1});
sc++;
}
t_ans += d;
}
if(sc == n)
ans = min(t_ans, ans);
}
cout << ans << "\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... |