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>
#define ll long long
using namespace std;
ll ans=LLONG_MAX,tmp=0;
int cnt=0;
bool vis[5007];
vector<int> g[5007];
void bfs(int src)
{
queue<pair<int,ll>> q;
q.emplace(src,1);
vis[src]=true;
while(!q.empty())
{
auto [u,dis]=q.front();
q.pop();
cnt++;
tmp+=dis;
for(auto v:g[u])
{
if(vis[v])continue;
vis[v]=true;
q.emplace(v,dis+1);
}
}
}
int main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
int k;
cin>>k;
while(k--)
{
int a;
cin>>a;
g[a].emplace_back(i);
}
}
for(int i=1;i<=n;i++)
{
cnt=0,tmp=0;
memset(vis,false,sizeof(vis));
bfs(i);
if(cnt!=n)continue;
ans=min(ans,tmp);
}
cout<<ans;
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'void bfs(int)':
bosses.cpp:17:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
17 | auto [u,dis]=q.front();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |