# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
705342 | ToroTN | Bosses (BOI16_bosses) | C++14 | 1 ms | 340 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
#define ll long long
ll n,m,sub,d[5005],u,type,sum,ans=1e9;
vector<ll> v[5005];
queue<ll> q;
int main()
{
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&m);
for(int j=1;j<=m;j++)
{
scanf("%lld",&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("%lld\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... |