#include <bits/stdc++.h>
using namespace std;
void maxCost(unordered_map<int, vector<pair<int, int>>> adj,
             unordered_map<int, bool> v, int S, int cost, int &mx) {
  if (mx < cost) {
    mx = cost;
  }
  v[S] = true;
  for (auto c : adj[S]) {
    if (!v[c.first]) {
      maxCost(adj, v, c.first, cost + c.second, mx);
    }
  }
}
int main() {
  unordered_map<int, vector<pair<int, int>>> adj;
  unordered_map<int, bool> v;
  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));
  }
  int mx = 0;
  maxCost(adj, v, 0, 0, mx);
  cout << mx << endl;
  return 0;
}
