#include <bits/stdc++.h>

#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
const ll INF = 1LL << 60;
vector<vector<P>> tree;
int h = 0;
vector<ll> height;
int mx = 0;
int node = 0;
P dfs(int cur, int parent) {
    height[cur] = h;
    h = 0;
    REP(i, tree[cur].size()) {
        if (tree[cur][i].first != parent) {
            h = height[cur] + tree[cur][i].second;
            if (h > mx) {
                mx = h;
                node = tree[cur][i].first;
            }
            dfs(tree[cur][i].first, cur);
        }
    }
    h = 0;
    // height.assign(height.size(), 0);
    return {node, mx};
}
int treediameter() { return dfs(dfs(0, -1).first, -1).second; }
int main() {
    int n;
    cin >> n;
    tree.resize(n);
    height.resize(n);
    REP(i, n - 1) {
        int s, t, w;
        cin >> s >> t >> w;
        tree[s].push_back({t, w});
        tree[t].push_back({s, w});
    }
    cout << treediameter() << endl;
}
