//Dedicated to my love, ivaziva
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
const int N=1e5+5;
int n;
ll ans=(ll)(1e18), dep[N];
vector<int> g[N];
void bfs(int sr) {
for (int i=1; i<=n; i++)
dep[i]=(ll)(1e18);
queue<int> q;
q.push(sr);
dep[sr]=1;
ll upd=0;
while (!q.empty()) {
int x=q.front();
q.pop();
upd+=dep[x];
for (int u:g[x]) {
if (dep[u]>dep[x]+1) {
dep[u]=dep[x]+1;
q.push(u);
}
}
}
for (int i=1; i<=n; i++) {
if (dep[i]==(ll)(1e18))
upd=(ll)(1e18);
}
ans=min(ans, upd);
}
int main () {
ios::sync_with_stdio(false), cin.tie(0);
cin >> n;
for (int i=1; i<=n; i++) {
int si; cin >> si;
while (si--) {
int v;
cin >> v;
g[v].pb(i);
}
}
ans=(ll)(1e18);
for (int i=1; i<=n; i++)
bfs(i);
cout << ans << '\n';
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... |