#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> g;
int dfs(int s, int p) {
  int cur = 0;
  for (auto t : g[s]) {
    int to = t.first;
    int w = t.second;
    if (to == p) continue;
    cur = max(cur, w + dfs(to, s));
  }
  return cur;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    g[a].push_back({b, w});
    g[b].push_back({a, w});
  }
  cout << dfs(0, -1);
}
