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;
const int MAX_N = 5005;
vector<int> G[MAX_N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
for (int i = 0; i < N; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int v;
cin >> v;
v--;
G[v].push_back(i);
}
}
int ans = INT_MAX;
for (int i = 0; i < N; i++) {
vector<int> depth(N);
queue<int> q;
q.push(i);
depth[i] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : G[u]) {
if (!depth[v]) {
depth[v] = depth[u] + 1;
q.push(v);
}
}
}
if (!count(depth.begin(), depth.end(), 0)) {
ans = min(ans, accumulate(depth.begin(), depth.end(), 0));
}
}
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... |