#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

struct mint {
    lint x; // typedef long long ll;
    mint(lint x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(lint t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct DP {
  int dp;
  DP(int dp=0):dp(dp){}
  DP operator+(const DP& a) const {
    return DP(max(dp,a.dp));
  }
  DP addRoot(int W){
      return DP(dp+W);
    }
};
 
vector<DP> dp[MAX_N];
DP ans[MAX_N];
vector<int> to[MAX_N];
map<pint,int> leng;

void addedge(int a,int b){
    to[a].push_back(b);
    to[b].push_back(a);
}
 
DP rerootdfs(int v, int p=-1) {
  DP dpSum;
  dp[v] = vector<DP>(to[v].size());
  rep(i,to[v].size()) {
    int u = to[v][i];
    int W=leng[pint(v,u)];
    if (u == p) continue;
    dp[v][i] = rerootdfs(u,v);
    dpSum = dpSum + dp[v][i];
  }
  return dpSum.addRoot(leng[pint(v,p)]);
}
void rerootbfs(int v, const DP& dpP=DP(), int p=-1) {
  int deg = to[v].size();
  rep(i,deg) if (to[v][i] == p) dp[v][i] = dpP;
 
  vector<DP> dpLeft(deg+1);
  rep(i,deg) dpLeft[i+1] = dpLeft[i] + dp[v][i];
  
  vector<DP> dpRight(deg+1);
  for (int i = deg-1; i >= 0; --i)
    dpRight[i] = dpRight[i+1] + dp[v][i];
  
  ans[v] = dpLeft[deg].addRoot(leng[pint(v,v)]);
 
  rep(i,deg) {
    int u = to[v][i];
    if (u == p) continue;
    DP d = dpLeft[i] + dpRight[i+1];
    rerootbfs(u, d.addRoot(leng[pint(u,v)]), v);
  }
}

void reroot(){
    rerootdfs(0);
    rerootbfs(0);
}

int main(void){
    int N;
    cin >> N;
    rep(i,N-1){
        int a,b,w;
        cin >> a >> b >> w;
        addedge(a,b);
        leng[pint(a,b)]=w;
        leng[pint(b,a)]=w;
    }
    reroot();
    int Ans=0;
    rep(i,N) Ans=max(Ans,ans[i].dp);
    cout << Ans << endl;
}


Measured memory_bytes: 63244