#include<bits/stdc++.h>
#define ep emplace
#define epb emplace_back
using namespace std;
int n,va[5007],ans=INT_MAX;
vector<int> adj[5007];
bool visited[5007];
void bfs(int node)
{
queue<int> q;
q.ep(node);
while(!q.empty())
{
auto u=q.front();
q.pop();
for(auto v:adj[u])
{
if(visited[v]) continue;
visited[v]=true;
va[v]=va[u]+1;
q.ep(v);
}
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
int num;
cin>>num;
while(num--)
{
int v;
cin>>v;
adj[v].epb(i);
}
}
for(int i=1;i<=n;i++)
{
memset(visited,false,sizeof(visited));
memset(va,0,sizeof(va));
visited[i]=true;
va[i]=1;
bfs(i);
int value=0;
for(int j=1;j<=n;j++)
value+=va[j];
// cout<<value<<"\n";
ans=min(ans,value);
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
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 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
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 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |