#include <bits/stdc++.h>
using namespace std;
const int max1 = 3e4 + 5;
vector<pair<int, int>> adj[max1];
int n, ans = 0;
bool vis[max1] = {false};
void dfs(int n, int val) {
  if (vis[n]) {
    return;
  }
  int temp = val;
  ans = max(ans, temp);
  vis[n] = true;
  for (auto x : adj[n]) {
    dfs(x.first, temp + x.second);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
      int t1, t2, len;
      cin >> t1 >> t2 >> len;
      adj[t1].push_back({t2, len});
      adj[t2].push_back({t1, len});
    }
    dfs(0, 0);
    cout << ans;
  }
}
