#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

static const int MAX = 100000;
static const int INF = __INT_MAX__;
class Edge{
    public:
    int t,w;
    Edge(int t,int w):t(t),w(w){}
};

vector<Edge>G[MAX];
int cnt,N,d[MAX];
bool V[MAX] = {false};

void bfs(int s){
    std::fill_n(d,N,INF);
    queue<int> q;
    q.push(s);
    d[s] = 0;

    while(!q.empty()){
        int u = q.front();
        q.pop();

        for(int i = 0;i < G[u].size();++i){
            Edge e = G[u][i];
            
            if(d[e.t] == INF){
                d[e.t] = d[u] + e.w;
                q.push(e.t);
            }
        }
    }
}

void solve(){
    bfs(0);
    int maxV = 0;
    int tgt = 0;
    
    for(int i = 0;i < N;++i){
        if(d[i] == INF)continue;
        if(maxV < d[i]){
            maxV = d[i];
            tgt = i;
        }
    }
    
    bfs(tgt);
    maxV = 0;
    for(int i = 0;i < N;++i){
        if(d[i] == INF)continue;
        maxV = max(maxV,d[i]);
    }
    cout << maxV << endl;
}

int main(){
    int s,t,w;
    cin >> N;
    
    for(int i = 0;i < N - 1;++i){
        cin >> s >> t >> w;
        G[s].push_back(Edge(t,w));
        G[t].push_back(Edge(s,w));
    }
    solve();
}

