| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 544724 | rainboy | Bosses (BOI16_bosses) | C11 | 541 ms | 604 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 <stdio.h>
#include <stdlib.h>
#define N 5000
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int *ej[N], eo[N];
void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
int solve(int n, int s) {
static int dd[N], qu[N];
int i, head, cnt, ans;
for (i = 0; i < n; i++)
dd[i] = n + 1;
head = cnt = 0;
dd[s] = 1, qu[head + cnt++] = s;
while (cnt) {
int d, o;
i = qu[cnt--, head++], d = dd[i] + 1;
for (o = 0; o < eo[i]; o++) {
int j = ej[i][o];
if (dd[j] > d)
dd[j] = d, qu[head + cnt++] = j;
}
}
if (head != n)
return INF;
ans = 0;
for (i = 0; i < n; i++)
ans += dd[i];
return ans;
}
int main() {
int n, i, ans;
scanf("%d", &n);
for (i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
for (i = 0; i < n; i++) {
int m;
scanf("%d", &m);
while (m--) {
int j;
scanf("%d", &j), j--;
append(j, i);
}
}
ans = INF;
for (i = 0; i < n; i++)
ans = min(ans, solve(n, i));
printf("%d\n", ans);
return 0;
}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... | ||||
