#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |