Submission #894712

#TimeUsernameProblemLanguageResultExecution timeMemory
894712rainboy두 로봇 (KOI18_robot)C11
100 / 100
39 ms17952 KiB
#include <stdio.h> #include <stdlib.h> #define N 100000 int max(int a, int b) { return a > b ? a : b; } int *ej[N], *ew[N], eo[N]; void append(int i, int j, int w) { int o = eo[i]++; if (o >= 2 && (o & o - 1) == 0) { ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]); ew[i] = (int *) realloc(ew[i], o * 2 * sizeof *ew[i]); } ej[i][o] = j, ew[i][o] = w; } int s, t, ans; int dfs(int p, int i, int sum, int mx) { int o; if (i == t) { ans = sum - mx; return 1; } for (o = eo[i]; o--; ) { int j = ej[i][o], w = ew[i][o]; if (j != p && dfs(i, j, sum + w, max(mx, w))) return 1; } return 0; } int main() { int n, h, i, j, w; scanf("%d%d%d", &n, &s, &t), s--, t--; for (i = 0; i < n; i++) { ej[i] = (int *) malloc(2 * sizeof *ej[i]); ew[i] = (int *) malloc(2 * sizeof *ew[i]); } for (h = 0; h < n - 1; h++) { scanf("%d%d%d", &i, &j, &w), i--, j--; append(i, j, w), append(j, i, w); } dfs(-1, s, 0, 0); printf("%d\n", ans); return 0; }

Compilation message (stderr)

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