#include <bits/stdc++.h>
using namespace std;
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
long long int n, z = 0, ans = 0;
vector<vector<pair<long long int, long long int>>> adj;
vector<bool> visited;
vector<long long int> v;
void DFS(long long int a) {
  visited[a] = true;
  for (long long int i = 0; i < adj[a].size(); i++) {
    if (visited[adj[a][i].first] != true) {
      z += adj[a][i].second;
      ans = max(ans, z);
      DFS(adj[a][i].first);
      z -= adj[a][i].second;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  adj.resize(n + 1);
  v.resize(n + 1);
  visited.resize(n + 1);
  visited.assign(n + 1, false);
  for (long long int i = 0; i < n - 1; i++) {
    long long int a;
    cin >> a;
    ;
    long long int b;
    cin >> b;
    ;
    long long int c;
    cin >> c;
    ;
    adj[a].push_back({b, c});
    adj[b].push_back({a, c});
  }
  DFS(0);
  cout << ans << endl;
  return 0;
}
