제출 #544724

#제출 시각아이디문제언어결과실행 시간메모리
544724rainboyBosses (BOI16_bosses)C11
100 / 100
541 ms604 KiB
#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) 메시지

bosses.c: In function 'append':
bosses.c:14:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   14 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
bosses.c: In function 'main':
bosses.c:49:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
bosses.c:55:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%d", &m);
      |   ^~~~~~~~~~~~~~~
bosses.c:59:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |    scanf("%d", &j), j--;
      |    ^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...