#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e4 + 4;
vector<vector<pair<int, int> > > adj(NMAX, vector<pair<int, int> >());
int res;
void dfs(int i, int par, int sofar) {
  bool leaf = true;
  for (int chi = 0; chi < adj[i].size(); chi++) {
    int node = adj[i][chi].first;
    int w = adj[i][chi].second;
    if (node == par) continue;
    dfs(node, i, sofar + w);
    leaf = false;
  }
  if (leaf) {
    res = max(res, sofar);
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    adj[a].push_back(make_pair(b, c));
    adj[b].push_back(make_pair(a, c));
  }
  dfs(0, -1, 0);
  cout << res;
  return 0;
}
