#include using namespace std; //#include //using namespace atcoder; using ll = long long int; using ull = unsigned long long int; using ld = long double; constexpr ll MAX = 2000000000000000000; constexpr ld PI = 3.14159265358979; constexpr ll MOD = 0;//2024948111; ld dotorad(ld K){ return PI * K / 180.0; } ld radtodo(ld K){ return K * 180.0 / PI; } mt19937 mt; void randinit(){ srand((unsigned)time(NULL));mt = mt19937(rand()); } ll N; vector> GG(300000),G(300000),WW(300000),W(300000); vector par(300000,-1); ll ans = 0; vector DP(300000,0); void dfs1(ll x){ vector s = {0}; for(ll i = 0; i < GG[x].size(); i++){ ll next = GG[x][i]; if(par[next] == -1){ G[x].emplace_back(next); W[x].emplace_back(WW[x][i]); par[next] = x; dfs1(next); s.emplace_back(DP[next] + WW[x][i]); } } sort(s.begin(),s.end(),greater()); ans = max(ans,s[0] + s[1]); DP[x] = s[0]; } int main(){ cin >> N; for(ll i = 0; i < N - 1; i++){ ll a,b,w; cin >> a >> b >> w; a--;b--; GG[a].emplace_back(b); GG[b].emplace_back(a); WW[a].emplace_back(w); WW[b].emplace_back(w); } par[0] = 0; dfs1(0); cout << ans << endl; }