#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 5e3 + 5;
int n;
vector<int> g[N];
int dp[N];
int bfs(int u) {
queue<int> q;
memset(dp, 0x3f, sizeof(dp));
dp[u] = 1;
q.emplace(u);
while(q.size()) {
int s = q.front(); q.pop();
for(int t : g[s]) if(dp[t] > dp[s] + 1) {
dp[t] = dp[s] + 1;
q.emplace(t);
}
}
int res = 0;
for(int i = 1; i <= n; ++i) res += dp[i];
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; ++i) {
int k, x; cin >> k;
while(k--) {
cin >> x;
g[x].push_back(i);
}
}
int ans = 1e9;
for(int i = 1; i <= n; ++i) ans = min(ans, bfs(i));
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |