#include <bits/stdc++.h>using namespace std;struct robot { int bigest; int cur; int length;};vector<pair<int,int>> edges[100010];int n, a, b;int nodes[100010];list<robot> q;int BFS();int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> a >> b; for (int i = 0; i < n-1; i++) { int t1, t2, t3; cin >> t1 >> t2 >> t3; edges[t1].push_back({ t2, t3 }); edges[t2].push_back({ t1, t3 }); } for (int i = 1; i <=n; i++) { nodes[i] = 2000000000; } cout << BFS() << "\n";}int BFS() { q.push_back({ 0, a, 0}); nodes[a] = 0; int result = 2000000000; while (!q.empty()) { int cur = q.front().cur, bigest = q.front().bigest, length = q.front().length; q.pop_front(); if (cur == b) { result = min(result, length - bigest); continue; } for (int i = 0; i < edges[cur].size(); i++) { int to = edges[cur][i].first, w = edges[cur][i].second; if (length + w < nodes[to]) { int bigger = max(bigest, w); nodes[to] = length + w; q.push_back({ bigger, to, nodes[to] }); } } } return result;}