#include #include #include using namespace std; using namespace atcoder; using ll = long long; #define all(A) A.begin(),A.end() using vll = vector; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) using Graph = vector>; Graph G; vll E; vector seen; ll k = 0; int main() { ll N; cin >> N; dsu D(N); while (1) { ll A, B, C; cin >> A >> B >> C; A--; B--; if (!D.same(A, B))D.merge(A, B); if (D.size(A) == N) { cout << C << endl; return 0; } } }