(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #412225

#TimeUsernameProblemLanguageResultExecution timeMemory
412225rainboyTraffic (IOI10_traffic)C11
100 / 100
845 ms144052 KiB
#include "traffic.h" #include <stdlib.h> #define N 1000000 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 sz[N], sum, c; void dfs(int p, int i) { int o; for (o = eo[i]; o--; ) { int j = ej[i][o]; if (j != p) { dfs(i, j); sz[i] += sz[j]; } } if (sz[i] >= (sum + 1) / 2 && (c == -1 || sz[c] > sz[i])) c = i; } int LocateCentre(int n, int *aa, int *ii, int *jj) { int h, i; for (i = 0; i < n; i++) ej[i] = (int *) malloc(2 * sizeof *ej[i]); for (h = 0; h < n - 1; h++) append(ii[h], jj[h]), append(jj[h], ii[h]); sum = 0; for (i = 0; i < n; i++) sum += aa[i], sz[i] = aa[i]; c = -1, dfs(-1, 0); return c; }

Compilation message (stderr)

traffic.c: In function 'append':
traffic.c:11:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   11 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...