#include <bits/stdc++.h>
using namespace std;
int level[100005], From[100005];
long long mxi, dist[100005];
vector<pair<int, int> > v[100005];
void dfs(int now, int prev, int dep) {
  level[now] = dep;
  From[now] = prev;
  int sz = v[now].size();
  for (int i = 0; i < sz; i++) {
    int to = v[now][i].first;
    if (to == prev) continue;
    dist[to] = dist[now] + v[now][i].second;
    dfs(to, now, dep + 1);
  }
  mxi = max(mxi, dist[now]);
  return;
}
int main() {
  int n;
  mxi = 0;
  cin >> n;
  int a, b, c;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b >> c;
    v[a].push_back({b, c});
    v[b].push_back({a, c});
  }
  dfs(0, -1, 0);
  cout << mxi << endl;
}
