This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |