#include //#include using namespace std; //using namespace atcoder; #define all(v) v.begin(),v.end() using ll = long long; using ull = unsigned long long; using lll = __int128; using vll=vector; using vvll = vector>; using P = pair; using vp=vector>; //using mint=modint1000000007; //using mint=modint998244353; const ll INF=1ll<<60; ll mod10=1e9+7; ll mod99=998244353; const double PI = acos(-1); #define rep(i,n) for (ll i=0;i=0;--i) #define rep2(i,a,n) for (ll i=a;i=n;--i) templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b>N1; vector ab1(N1); rep(i,N1-1){ ll a,b;cin>>a>>b;a--;b--;ll c;cin>>c; ab1[a].push_back({c,b}); ab1[b].push_back({c,a}); } vll dp1(N1); auto dfs1 = [&](auto&& dfs1,ll a,ll b,vector& ab,vll& dp) -> void { for(auto [c,to]:ab[a]){ if(to==b) continue; dfs1(dfs1,to,a,ab,dp); chmax(dp[a],dp[to]+c); } }; auto dfs2 = [&](auto&& dfs2,ll a,ll b,ll val,vector& ab,vll& dp) -> void { vector

d; d.push_back({0,-1}); for(auto [c,to]:ab[a]){ if(to==b) d.push_back({val+c,to}); else d.push_back({c+dp[to],to}); } sort(all(d));reverse(all(d)); ll sum=d[0].first+d[1].first; for(auto [c,to]:ab[a]){ if(to==b) continue; if(to==d[0].second) dfs2(dfs2,to,a,d[1].first,ab,dp); else dfs2(dfs2,to,a,d[0].first,ab,dp); } dp[a]=d[0].first; }; dfs1(dfs1,0,0,ab1,dp1); dfs2(dfs2,0,0,0,ab1,dp1); ll ans=0; rep(i,N1) chmax(ans,dp1[i]); cout << ans << endl; return 0; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll T=1;//cin>>T; rep(i,T) solve(); }