// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_A&lang=jp
#include <bits/stdc++.h>
using namespace std;

struct Diameter {
  Diameter () {}
  Diameter (int n) : G(n) {}

  struct edge {
    edge () {}
    edge (int to, int cost) : to(to), cost(cost) {}

    int to, cost;
  };

  using P = pair<int, int>;

  const P id = make_pair(0, -1);
  vector<vector<edge>> G;
  pair<P, int> max_pair;

  void add_edge(int u, int v, int cost) {
    G[u].push_back(edge(v, cost));
    G[v].push_back(edge(u, cost));
  }

  void add_edge(int u, int v) {
    add_edge(u, v, 1);
  }

  P dfs(int v, int pre) {
    P res = id;
    for (const auto &e : G[v]) {
      if (e.to == pre) continue;
      P p = dfs(e.to, v);
      p.first += e.cost;
      res = max(res, p);
    }

    if (res == id) {
      res = make_pair(0, v);
    }
    return res;
  }

  int dist() {
    P l = dfs(0, -1);
    P r = dfs(l.second, -1);
    max_pair = make_pair(P(l.second, r.second), r.first);
    return r.first;
  }
};

int main() {
  int n;
  cin >> n;

  Diameter d(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    d.add_edge(u, v, c);
  }

  cout << d.dist() << endl;
}