This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n,a,b,mn=INT_MAX;
vector<int> v[5005];
bool visited[5005];
queue<pair<int,int>> q;
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i=1;i<=n;i++){
cin >> a;
for(int j=0;j<a;j++) cin >> b,v[b].push_back(a);
}
for(int i=1;i<=n;i++){
q.push({1,i});
int sum=0,cnt=0;
memset(visited,0,sizeof(visited));
while(!q.empty()){
int now=q.front().second,cost=q.front().first; q.pop();
if(visited[now]) continue; visited[now]=1;
sum+=cost; cnt++;
for(auto e:v[now]) if(!visited[e]) q.push({cost+1,e});
}
if(cnt==n) mn=min(mn,sum);
}
cout << mn;
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'int main()':
bosses.cpp:22:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
22 | if(visited[now]) continue; visited[now]=1;
| ^~
bosses.cpp:22:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
22 | if(visited[now]) continue; visited[now]=1;
| ^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |