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;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> v[n];
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
while (k--) {
int u;
cin >> u;
u--;
v[u].push_back(i);
}
}
bitset<5000> bs;
bs.reset();
long long ans = 1e9;
int dep[n];
for (int i = 0; i < n; ++i) {
bs.reset();
queue<int> q;
q.push(i);
dep[i] = 1;
long long sum = 1;
bs[i] = 1;
while (!q.empty()) {
int s = q.front();
q.pop();
for (auto u : v[s]) {
if (bs[u] == 0) {
bs[u] = 1;
q.push(u);
dep[u] = dep[s] + 1;
sum += dep[u];
}
}
}
for (int i = 0; i < n; ++i) {
if (bs[i] == 0) {
sum += 1e9;
}
}
ans = min(ans, sum);
}
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... |