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 int long long
#define fi first
#define se second
using namespace std;
const int inff = 1e18;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<vector<int>> v(n + 1);
for (int i = 1; i <= n; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int x;
cin >> x;
v[x].push_back(i);
}
}
int ans = inff;
for (int i = 1; i <= n; i++) {
vector<int> d(n + 1, -1), q(1, i);
vector<vector<int>> g(n + 1);
d[i] = 0;
for (int j = 0; j < (int)q.size(); j++) {
int x = q[j];
for (auto z : v[x]) {
if (d[z] == -1) {
d[z] = d[x] + 1;
g[x].push_back(z);
q.push_back(z);
}
}
}
if ((int)q.size() < n) continue;
int res = 0;
vector<int> val(n + 1);
for (int j = n - 1; j >= 0; j--) {
int x = q[j];
val[x] = 1;
for (auto z : v[x]) {
val[x] += val[z];
}
res += val[x];
}
ans = min(ans, res);
}
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... |