#include <bits/stdc++.h>
using namespace std;
int n,k,pom;
vector<int> mat[5003];
int dist[5003];
queue<int> q;
long long cnt[5003],res;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> k;
for(int j = 0; j < k; j++){
cin >> pom;
mat[pom].push_back(i);
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++)
dist[j] = 9999999;
dist[i] = 1;
q.push(i);
while(!q.empty()){
pom = q.front();
q.pop();
for(auto x: mat[pom]){
if(dist[x] != 9999999)
continue;
dist[x] = dist[pom] + 1;
q.push(x);
}
}
for(int j = 1; j <= n; j++){
cnt[i] += dist[j];
}
}
res = cnt[1];
for(int i = 2; i <= n; i++){
res = min(res,cnt[i]);
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
508 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
508 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
7 ms |
632 KB |
Output is correct |
13 |
Correct |
6 ms |
632 KB |
Output is correct |
14 |
Correct |
166 ms |
732 KB |
Output is correct |
15 |
Correct |
32 ms |
708 KB |
Output is correct |
16 |
Correct |
677 ms |
856 KB |
Output is correct |
17 |
Correct |
934 ms |
988 KB |
Output is correct |
18 |
Correct |
924 ms |
904 KB |
Output is correct |