# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
705340 | ToroTN | Bosses (BOI16_bosses) | C++14 | 1 ms | 420 KiB |
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;
#define pb push_back
int n,m,sub,d[5005],u,type,sum,ans=1e9;
vector<int> v[5005];
queue<int> q;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&m);
for(int j=1;j<=m;j++)
{
scanf("%d",&sub);
v[sub].pb(i);
}
}
for(int i=1;i<=n;i++)
{
memset(d,-1,sizeof d);
d[i]=1;
q.push(i);
while(!q.empty())
{
u=q.front();
q.pop();
for(auto node:v[u])
{
if(d[node]==-1)
{
d[node]=d[u]+1;
q.push(node);
}
}
}
sum=0;
type=0;
for(int j=1;j<=n;j++)
{
if(d[j]==-1)type=-1;
sum+=d[j];
}
if(type==0)
{
ans=min(ans,sum);
}
}
printf("%d\n",sum);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |