#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
// const ll INF = 1LL << 60;
const ll MOD = 1000000007;
const int INF = 1000000000;
const int MAX = 300000;

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
//------------------------------------------------------------------------------------------------------------------------------

vector<vector<P>> G;
int mxi, mx;

void dfs(int chi, int par=-1, int d=0) {
    for (auto p : G[chi]) {
        int nv = p.first;
        int w = p.second;
        if (nv == par) {
            continue;
        }

        if (mx < d + w) {
            mx = d + w;
            mxi = nv;
        }
        dfs(nv, chi, d + w);
    }
}

int main(void) {
    int N;
    cin >> N;
    G.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        G[s].push_back(P(t, w));
        G[t].push_back(P(s, w));
    }
    mxi = 0;
    mx = 0;
    dfs(mxi);
    dfs(mxi);
    cout << mx << endl;
}
