#include<bits/stdc++.h>
using namespace std;
#define task "task"
#define ii pair<int,int>
#define fi first
#define se second
//#define int long long
#define ll long long
#define ld double
#define mp make_pair
#define lg2 30
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define base 29
#define eps 1e-8
int dx[]= {0LL,0LL,1,-1,1,1,-1,-1};
int dy[]= {1,-1,0LL,0LL,1,-1,1,-1};
const int maxn=5e3+1;
const int mod=1e9+7;
int n,a[maxn],m,k,dist[maxn];
vector<int>e[maxn];
void init()
{
cin>>n;
for(int i=1;i<=n;i++)
{
int k;
cin>>k;
while(k--)
{
int x;
cin>>x;
e[x].push_back(i);
}
}
}
void process()
{
ll ans=1e18;
for(int r=1;r<=n;r++)
{
memset(dist,0,sizeof(dist));
dist[r]=1;
queue<int>q;
q.push(r);
while(!q.empty())
{
int u=q.front();
q.pop();
for(int v:e[u])
{
if(!dist[v])
{
dist[v]=dist[u]+1;
q.push(v);
}
}
}
ll tmp=0;
bool ok=true;
for(int i=1;i<=n;i++)
{
if(!dist[i])ok=false;
tmp+=1LL*dist[i];
}
if(ok)ans=min(ans,tmp);
}
cout<<ans;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
init();
process();
cerr <<endl<< "TIME : " << clock() * 0.001 << "s" << endl ;
}
Compilation message (stderr)
bosses.cpp: In function 'int main()':
bosses.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |