#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

struct Edge {
  int t, w;
  Edge() {}
  Edge(int t, int w): t(t), w(w) {}
};

using ve = vector<Edge>;
using vve = vector<ve>;
int n;
vve tree;

void bfs(vi &d, int s) {
  queue<int> q;
  q.push(s);
  
  vector<bool> visited(n);
  while (!q.empty()) {
    int c = q.front(); q.pop();
    visited[c] = true;

    for (auto nt: tree[c]) {
      int t = nt.t, w = nt.w;
      
      if (visited[t]) continue;

      d[t] = w + d[c];

      q.push(t);
    }
  }
}

int solve() {
  vi d1(n);
  bfs(d1, 0);

  int max_e = 0;
  rep(i, n)
    if (d1[max_e] < d1[i]) max_e = i;
  
  vi d2(n);
  bfs(d2, max_e);
  rep(i, n)
    if (d2[max_e] < d2[i]) max_e = i;
  
  return d2[max_e];
}

int main() {
  cin >> n;
  
  int s, t, w;
  tree.resize(n);
  rep(i, n - 1) {
    cin >> s >> t >> w;
    tree[s].push_back(Edge(t, w));
    tree[t].push_back(Edge(s, w));
  }
  
  int max_d = solve();
  cout << max_d << endl;
}

