#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

template<typename costType = int>
class TreeDiameter {
private:
    std::vector<std::vector<std::pair<int, costType>>> Graph;
    std::vector<costType> dist;
    void makeTreeDfs(const std::vector<std::vector<int>> &G, int now, int prev) {
        for (auto &&e : G[now]) if (e != prev) {
            Graph[now].emplace_back(std::make_pair(e, 1));
            Graph[e].emplace_back(std::make_pair(now, 1));
            makeTreeDfs(G, e, now);
        }
    }
    void calcTreeDiameterDfs(int now, int prev) {
        for (auto &&e : Graph[now]) if (e.first != prev) {
            dist[e.first] = dist[now] + e.second;
            calcTreeDiameterDfs(e.first, now);
        }
    }
public:
    TreeDiameter() {}
    TreeDiameter(int n) {
        init(n);
    }
    void init(int n) {
        Graph.resize(n);
        dist.resize(n, 0);
    }
    TreeDiameter(const std::vector<std::vector<std::pair<int, costType>>> &G) {
        Graph = G;
        dist.resize(G.size());
    }
    TreeDiameter(const std::vector<std::vector<int>> &G) {
        Graph.resize(G.size());
        makeTreeDfs(G, 0, -1);
        dist.resize(G.size());
    }
    void addEdge(int u, int v, costType cost) {
        Graph[u].emplace_back(std::make_pair(v, cost));
        Graph[v].emplace_back(std::make_pair(u, cost));
    }
    costType calcTreeDiameter() {
        calcTreeDiameterDfs(0, -1);
        const int root = std::distance(std::begin(dist), std::max_element(std::begin(dist), std::end(dist)));
        dist[root] = 0;
        calcTreeDiameterDfs(root, -1);
        return *std::max_element(std::begin(dist), std::end(dist));
    }
};

TreeDiameter<int> diam;
int n;

int main(void) {
    scanf("%d", &n);
    diam.init(n);
    REP(i, n - 1) {
        int s, t, w;
        scanf("%d%d%d", &s, &t, &w);
        diam.addEdge(s, t, w);
    }
    printf("%d\n", diam.calcTreeDiameter());
}

Measured memory_bytes: 11736