#include using namespace std; using ll = long long; const int iinf = 1e9; const ll inf = 1e18; template ostream& operator<<(ostream &o, vector v) { for (int i = 0; i < v.size(); i++) o << v[i] << (i+1sync_with_stdio(false); int N; cin >> N; vector>> adj(N+1); for(int i = 0; i < N-1; i++){ int u, v; ll w; cin >> u >> v >> w; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } vector parent(N+1, 0), order; order.reserve(N); stack st; st.push(1); parent[1] = -1; while(!st.empty()){ int u = st.top(); st.pop(); order.push_back(u); for(auto [v,w]: adj[u]){ if(parent[v] == 0){ parent[v] = u; st.push(v); } } } vector bestDown(N+1, 0); ll ans = 0; for(int idx = N-1; idx >= 0; idx--){ int u = order[idx]; vector cand; cand.reserve(adj[u].size()); for(auto [v,w]: adj[u]){ if(parent[v] == u){ cand.push_back(bestDown[v] + w); } } ll mx = 0; for(ll x : cand) if(x > mx) mx = x; bestDown[u] = mx; ll x = 0, y = 0; for(ll v : cand){ if(v > x){ y = x; x = v; } else if(v > y){ y = v; } } ans = max(ans, x + y); } if(ans > 0) cout << ans << "\n"; else cout << 0 << "\n"; return 0; }