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>
#define pb push_back
using namespace std;
const int N = 5e3 + 10, INF = 1e9;
int n, ans = INF;
vector<int> G[N];
void bfs(int v) {
queue<int> q;
vector<int> h(N, INF), H(N, 0);
int res = 0, ps = 0;
h[v] = 0;
q.push(v);
while (q.size()) {
int u = q.front();
q.pop();
for (auto e : G[u])
if (h[u] + 1 < h[e]) {
h[e] = h[u] + 1;
q.push(e);
}
}
for (int i = 0; i < n; i++) {
if (h[i] == INF) continue;
H[h[i]]++;
}
for (int i = n; i >= 0; i--)
ps += H[i], res += ps;
ans = min(ans, res);
}
int main() {
ios:: sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
int m, x;
cin >> m;
for (int j = 0; j < m; j++) {
cin >> x;
G[--x].pb(i);
}
}
for (int i = 0; i < n; i++) bfs(i);
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... |