#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template > T &chmin(T &l, T r, Compare &&f = less()) { return l = min(l, r, f); } template > T &chmax(T &l, T r, Compare &&f = less()) { return l = max(l, r, f); } #include #include using bint = boost::multiprecision::int512_t; int main() { const bint inf = numeric_limits::max() / 2; int n; cin >> n; auto edge = vec>(uns, n * (n - 1) / 2); for (auto &[a, b, c] : edge) { cin >> a >> b >> c; --a; --b; } sort(begin(edge), end(edge), [](auto &x, auto &y) { return get<2>(x) < get<2>(y); }); auto kruskal = [&](const bint &lim) -> optional { atcoder::dsu dsu(n); bint sum = 0; for (auto &[a, b, c] : edge) { if (dsu.same(a, b) || lim < c) { continue; } dsu.merge(a, b); sum += c; } if (size(dsu.groups()) != 1) { return nullopt; } return sum; }; bint cost = *kruskal(inf); bint l = 0, r = inf; while (1 < r - l) { bint m = l + (r - l) / 2; auto c = kruskal(m); if (!c || cost < *c) { l = m; } else { r = m; } } cout << r << endl; }