#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; template using V=vector; template using VV=V>; ll dp[200200],dp2[200200]; V> G[200200]; const ll INF=1e18; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; rep(i,n-1){ int u,v; ll w; cin>>u>>v>>w; u--,v--; G[u].push_back({v,w}); G[v].push_back({u,w}); } auto f=[&](auto f,int v,int p)->void{ V A; for(auto [nv,w]:G[v]){ if(nv==p) continue; f(f,nv,v); A.push_back(max(w,w+dp[nv])); } sort(ALL(A)); reverse(ALL(A)); int a=A.size(); if(a==0) return; dp[v]=A[0]; dp2[v]=A[0]; if(a>1 && A[1]>0) dp2[v]+=A[1]; }; f(f,0,-1); ll ans=-INF; rep(i,n) ans=max(ans,dp2[i]); cout<