#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long ninf = -1 * inf;
long long dx[4] = {1, -1, 0, 0};
long long dy[4] = {0, 0, 1, -1};
char dir[4] = {'D', 'U', 'R', 'L'};
struct Node {
  long long x, y, l, r;
};
void solve(long long ca) {
  long long n, a, b, w;
  cin >> n;
  vector<vector<pair<long long, long long>>> graph(n);
  for (long long i = 0; i < n - 1; i++) {
    cin >> a >> b >> w;
    graph[a].push_back({b, w});
    graph[b].push_back({a, w});
  }
  priority_queue<pair<long long, long long>> q;
  q.push({0, 0});
  vector<long long> dist(n, INT_MIN);
  dist[0] = 0;
  vector<bool> visited(n, false);
  while (!q.empty()) {
    pair<long long, long long> curr = q.top();
    q.pop();
    if (visited[curr.second]) continue;
    visited[curr.second] = true;
    for (pair<long long, long long> dest : graph[curr.second]) {
      if (visited[dest.first]) continue;
      if (dist[dest.first] < dist[curr.second] + dest.second) {
        dist[dest.first] = dist[curr.second] + dest.second;
        q.push({dist[dest.first], dest.first});
      }
    }
  }
  long long res = INT_MIN;
  for (long long i = 0; i < n; i++) {
    if (dist[i] != INT_MAX) res = max(res, dist[i]);
  }
  cout << res;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  long long t = 1, ca;
  ca = 1;
  while (t--) {
    solve(ca);
    ca++;
  }
}
