#include using namespace std; using ll = long long; const ll INF = (ll)1e18; int N; vector>> adj; ll ans = -INF; vector seen; ll dfs(int v, int par){ vector child_vals; for(auto [u, w] : adj[v]){ if(u == par) continue; ll sub = dfs(u, v) + w; child_vals.push_back(sub); } sort(child_vals.rbegin(), child_vals.rend()); ll best_down = child_vals.empty() ? 0 : child_vals[0]; ans = max(ans, best_down); if(child_vals.size() >= 2){ ans = max(ans, child_vals[0] + child_vals[1]); } return best_down; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; adj.assign(N+1, {}); for(int i = 1; i < N; i++){ int u, v; ll w; cin >> u >> v >> w; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } dfs(1, -1); cout << ans << "\n"; return 0; }