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 INF 0x3f3f3f3f
using namespace std;
void minSelf(int &x, int y) {
if (y < x) {
x = y;
}
}
void testCase() {
int n;
cin >> n;
vector<vector<int>> g(n + 1);
for (int v = 1; v <= n; ++v) {
int k;
cin >> k;
for (int i = 0; i < k; ++i) {
int u;
cin >> u;
g[u].emplace_back(v);
}
}
int ans = INF;
for (int root = 1; root <= n; ++root) {
vector<int> level(n + 1);
level[root] = 1;
queue<int> q;
q.emplace(root);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : g[u]) {
if (!level[v]) {
level[v] = level[u] + 1;
q.emplace(v);
}
}
}
if (*min_element(level.begin() + 1, level.end())) {
minSelf(ans, accumulate(level.begin() + 1, level.end(), 0));
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 0; tc < tests; ++tc) {
testCase();
}
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... |