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;
#define int long long
#define ld long double
#define ar array
const int LOG = 20;
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 3e5 + 20;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,avx,bmi,bmi2")
vector<int> g[N];
int n;
int bfs(int x){
int d[n];
memset(d, 0, sizeof d);
d[x] = 1;
queue<int> q;
q.push(x);
while(q.size()){
int u = q.front();
q.pop();
for(auto v: g[u]){
if(d[v])continue;
d[v] = d[u] + 1;
q.push(v);
}
}
int ans = 0;
for(int i = 0;i < n;i++){
if(!d[i])return INF;
ans += d[i];
}
return ans;
}
signed main(){ios_base::sync_with_stdio(false);
cin>>n;
for(int i = 0;i < n;i++){
int k;
cin>>k;
while(k--){
int x;
cin>>x;
--x;
g[x].push_back(i);
}
}
int ans = INF;
for(int i = 0;i < n;i++)ans = min(ans, bfs(i));
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... |