This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"
vector<vector<int>> g;
vector<bool> vis;
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
g.resize(n);
vis.resize(n);
for(int i=0; i<n; ++i){
int k; cin >> k;
for(int j=0; j<k; ++j){
int x; cin >> x;
g[x-1].push_back(i);
}
}
int ans = 1e18;
for(int root=0; root<n; ++root){
for(int i=0; i<n; ++i) vis[i] = false;
queue<pair<int, int>> q;
vis[root] = true;
q.emplace(root, 1);
bool ok = true;
int curr = 0;
while(!q.empty()){
int u = q.front().first, d = q.front().second;
q.pop();
curr += d;
for(int v : g[u]){
if(!vis[v]){
vis[v] = true;
q.emplace(v, d+1);
}
}
}
for(int i=0; i<n; ++i) if(!vis[i]) ok = false;
if(ok) ans = min(ans, curr);
}
cout << ans nl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |