Submission #491150

#TimeUsernameProblemLanguageResultExecution timeMemory
491150rainboyPastiri (COI20_pastiri)C11
8 / 100
291 ms33332 KiB
#include <stdio.h> #include <stdlib.h> #define N 500000 int *ej[N], eo[N]; void append(int **ej, int *eo, 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 main() { static int qu[N]; static char sheep[N]; int n, k, h, i, j, cnt; scanf("%d%d", &n, &k); 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(ej, eo, i, j), append(ej, eo, j, i); } for (h = 0; h < k; h++) { scanf("%d", &i), i--; sheep[i] = 1; } cnt = 0; for (i = -1, j = 0; j < n; j++) if (sheep[j]) { if (i == -1) i = j; else if ((i + j) % 2 != 0) qu[cnt++] = i, i = j; else qu[cnt++] = (i + j) / 2, i = -1; } if (i != -1) qu[cnt++] = i, i = -1; printf("%d\n", cnt); for (h = 0; h < cnt; h++) printf("%d ", qu[h] + 1); printf("\n"); return 0; }

Compilation message (stderr)

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