#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> g;
vector<int> d;
void BFS() {
  d[0] = 0;
  queue<int> q;
  q.push(0);
  vector<bool> v(g.size());
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    int di = d[t];
    v[t] = true;
    for (int i = 0; i < g[t].size(); i++) {
      int z = g[t][i].first;
      if (!v[z]) {
        d[z] = di + g[t][i].second;
        q.push(z);
      }
    }
  }
}
int ans = INT_MIN;
void DFS(int s, int k, vector<bool>& v) {
  v[s] = true;
  if (k > ans) ans = k;
  for (int i = 0; i < g[s].size(); i++) {
    int x = g[s][i].first;
    int y = g[s][i].second;
    if (!v[x]) {
      DFS(x, k + y, v);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  g.resize(n);
  d.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    g[u].push_back(make_pair(v, c));
    g[v].push_back(make_pair(u, c));
  }
  vector<bool> v(n);
  DFS(0, 0, v);
  cout << ans;
  return 0;
}
