Submission #894712

# Submission time Handle Problem Language Result Execution time Memory
894712 2023-12-28T18:41:34 Z rainboy None (KOI18_robot) C
100 / 100
39 ms 17952 KB
#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

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 time Memory Grader output
1 Correct 37 ms 17748 KB Output is correct
2 Correct 25 ms 10064 KB Output is correct
3 Correct 25 ms 13784 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 4 ms 2140 KB Output is correct
6 Correct 4 ms 2140 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 2392 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 8 ms 3556 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 8 ms 4088 KB Output is correct
14 Correct 9 ms 3932 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 15 ms 5804 KB Output is correct
17 Correct 13 ms 7772 KB Output is correct
18 Correct 15 ms 7260 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 15 ms 6808 KB Output is correct
21 Correct 19 ms 9308 KB Output is correct
22 Correct 20 ms 10324 KB Output is correct
23 Correct 2 ms 1372 KB Output is correct
24 Correct 24 ms 12208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 9984 KB Output is correct
2 Correct 26 ms 13648 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 5 ms 1884 KB Output is correct
6 Correct 4 ms 2140 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 9 ms 3532 KB Output is correct
9 Correct 6 ms 2908 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 9 ms 3928 KB Output is correct
12 Correct 11 ms 3928 KB Output is correct
13 Correct 1 ms 856 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 14 ms 4952 KB Output is correct
16 Correct 17 ms 7772 KB Output is correct
17 Correct 15 ms 7004 KB Output is correct
18 Correct 19 ms 7152 KB Output is correct
19 Correct 21 ms 10584 KB Output is correct
20 Correct 25 ms 8276 KB Output is correct
21 Correct 3 ms 1372 KB Output is correct
22 Correct 3 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1112 KB Output is correct
16 Correct 0 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 10068 KB Output is correct
2 Correct 39 ms 9808 KB Output is correct
3 Correct 39 ms 17880 KB Output is correct
4 Correct 24 ms 9936 KB Output is correct
5 Correct 32 ms 13916 KB Output is correct
6 Correct 38 ms 17952 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 4 ms 2136 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1884 KB Output is correct
13 Correct 5 ms 1884 KB Output is correct
14 Correct 4 ms 2140 KB Output is correct
15 Correct 0 ms 428 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 5 ms 2488 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 7 ms 3676 KB Output is correct
20 Correct 10 ms 3164 KB Output is correct
21 Correct 7 ms 3104 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 8 ms 3964 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 8 ms 4024 KB Output is correct
29 Correct 11 ms 3928 KB Output is correct
30 Correct 11 ms 3928 KB Output is correct
31 Correct 1 ms 856 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 12 ms 5980 KB Output is correct
35 Correct 3 ms 856 KB Output is correct
36 Correct 23 ms 4952 KB Output is correct
37 Correct 15 ms 4952 KB Output is correct
38 Correct 17 ms 7736 KB Output is correct
39 Correct 2 ms 856 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 14 ms 7256 KB Output is correct
42 Correct 2 ms 860 KB Output is correct
43 Correct 15 ms 7004 KB Output is correct
44 Correct 17 ms 7152 KB Output is correct
45 Correct 18 ms 7148 KB Output is correct
46 Correct 18 ms 9104 KB Output is correct
47 Correct 20 ms 10428 KB Output is correct
48 Correct 25 ms 8476 KB Output is correct
49 Correct 25 ms 8272 KB Output is correct
50 Correct 2 ms 1368 KB Output is correct
51 Correct 3 ms 1116 KB Output is correct
52 Correct 3 ms 1116 KB Output is correct
53 Correct 24 ms 12116 KB Output is correct