#include <bits/stdc++.h>
using namespace std;
vector<int> W, sorted, weight;
void init(int n, int m, vector<int> U, vector<int> V, vector<int> W) {
weight.resize(n);
for (int i = 0; i < n-1; i++)
weight[V[i]] = W[i];
sorted.resize(n-1);
iota(sorted.begin(), sorted.end(), 1);
sort(sorted.begin(), sorted.end(), [&](int x, int y) { return weight[x] < weight[y]; });
}
int getMinimumFuelCapacity(int x, int y) {
for (int z : sorted) {
if (x != z && x != y) {
return max(weight[x], max(weight[y], weight[z]));
}
}
return -1;
}