| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 544724 | rainboy | Bosses (BOI16_bosses) | C11 | 541 ms | 604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}컴파일 시 표준 에러 (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... | ||||
