제출 #544720

#제출 시각아이디문제언어결과실행 시간메모리
544720rainboyNetwork (BOI15_net)C11
100 / 100
359 ms45840 KiB
#include <stdio.h> #include <stdlib.h> #define N 500000 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 qu[N], cnt; void dfs(int p, int i) { int o; if (eo[i] == 1) qu[cnt++] = i; for (o = 0; o < eo[i]; o++) { int j = ej[i][o]; if (j != p) dfs(i, j); } } int main() { int n, h, i, j; scanf("%d", &n); for (i = 0; i < n; i++) ej[i] = (int *) malloc(2 * sizeof *ej[i]); for (h = 0; h < n - 1; h++) { scanf("%d%d", &i, &j), i--, j--; append(i, j), append(j, i); } i = 0; while (eo[i] == 1) i++; dfs(-1, i); printf("%d\n", (cnt + 1) / 2); for (h = 0; h < (cnt + 1) / 2; h++) printf("%d %d\n", qu[h] + 1, qu[h + cnt / 2] + 1); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

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