# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
156295 | Lawliet | Bosses (BOI16_bosses) | C++14 | 1035 ms | 840 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>
#define MAX 5010
#define INF 1000000010
using namespace std;
int n;
int n1, n2;
int ans[MAX];
int dist[MAX];
bool marc[MAX];
vector<int> grafo[MAX];
queue<int> q;
void add(int cur, int root, int d)
{
q.push( cur );
dist[ cur ] = d;
marc[ cur ] = true;
ans[ root ] += dist[ cur ];
}
void BFS(int s)
{
memset(marc , 0 , sizeof( marc ));
add( s , s , 1 );
while( !q.empty() )
{
int cur = q.front();
q.pop();
for(int i = 0 ; i < grafo[ cur ].size() ; i++)
{
int prox = grafo[ cur ][ i ];
if( !marc[prox] )
add( prox , s , dist[ cur ] + 1 );
}
}
}
int main()
{
scanf("%d",&n);
for(int i = 1 ; i <= n ; i++)
{
scanf("%d",&n1);
for(int j = 1 ; j <= n1 ; j++)
{
scanf("%d",&n2);
grafo[ n2 ].push_back( i );
}
}
int mn = INF;
for(int i = 1 ; i <= n ; i++)
{
BFS( i );
bool reachAll = true;
for(int j = 1 ; j <= n ; j++)
reachAll = reachAll && marc[ j ];
if( reachAll ) mn = min(mn , ans[ i ]);
}
printf("%d\n",mn);
}
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... |