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;
int d[5001], val[5001], q[5001];
vector<int> v[5001], g[5001];
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++) {
for (int j = 1; j <= n; j++) {
q[j] = -1;
d[j] = -1;
g[j].clear();
}
int ptr = 0;
q[++ptr] = i;
d[i] = 0;
for (int j = 1; j <= n; j++) {
int x = q[j];
if (x == -1) break;
for (auto z : v[x]) {
if (d[z] == -1) {
d[z] = d[x] + 1;
g[x].push_back(z);
q[++ptr] = z;
}
}
}
if (ptr < n) continue;
int res = 0;
for (int j = n; j >= 1; j--) {
int x = q[j];
val[x] = 1;
for (auto z : g[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... |