#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int>>> g;
int third_smallest;
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
g.assign(N, {});
vector<int> all;
for (int i = 0; i < M; i++) {
g[U[i]].push_back({V[i], W[i]});
g[V[i]].push_back({U[i], W[i]});
all.push_back(W[i]);
}
sort(all.begin(), all.end());
third_smallest = all[2];
}
int getmaxpath(int X, int Y) {
if (X == Y) return 0;
vector<int> vis(g.size(), 0);
queue<pair<int,int>> q;
q.push({X, 0});
vis[X] = 1;
while (!q.empty()) {
int u = q.front().first;
int mx = q.front().second;
q.pop();
if (u == Y) return mx;
for (auto e : g[u]) {
int v = e.first;
int w = e.second;
if (vis[v]) continue;
vis[v] = 1;
q.push({v, max(mx, w)});
}
}
return 0;
}
int getMinimumFuelCapacity(int X, int Y) {
return max(third_smallest, getmaxpath(X, Y));
}