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 rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vi adj[n+1];
rep (i,1,n) {
int k; cin >> k;
rep (j,1,k) {
int x; cin >> x;
adj[x].pb(i);
}
}
int ans = 1e9;
rep (i,1,n) {
int d[n+1] = {};
d[i] = 1;
queue<int> q;
q.push(i);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : adj[u]) {
if (!d[v]) {
d[v] = d[u]+1;
q.push(v);
}
}
}
int suc = 1, sum = 0;
rep (j,1,n) {
sum += d[j];
suc &= (d[j]>0);
}
if (suc) ans = min(ans, sum);
}
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... |