# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98340 | Kastanda | Bosses (BOI16_bosses) | C++11 | 545 ms | 768 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 pb push_back
using namespace std;
const int N = 5005;
int n, Mn = INT_MAX, D[N], qu[N];
vector < int > Adj[N];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
int len, a;
scanf("%d", &len);
for (; len; len --)
scanf("%d", &a), Adj[a].pb(i);
}
for (int i = 1; i <= n; i++)
{
int l = 0, r = 0;
int sum = 0, cnt = 0;
memset(D, -1, sizeof(D));
qu[r ++] = i; D[i] = 1;
while (r - l)
{
int v = qu[l ++];
sum += D[v];
cnt ++;
for (int &u : Adj[v])
if (D[u] == -1)
qu[r ++] = u, D[u] = D[v] + 1;
}
if (cnt == n)
Mn = min(Mn, sum);
}
return !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... |