#include <bits/stdc++.h>
const int MAXN = 200000;
using namespace std;
int dp[MAXN];
vector<pair<int, int>> G[MAXN];
void dfs(int u, int pr) {
  for (auto x : G[u]) {
    if (x.first == pr) continue;
    dfs(x.first, u);
    dp[u] = max(dp[u], dp[x.first] + x.second);
  }
}
void mainp() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }
  dfs(0, 0);
  cout << dp[0] << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  mainp();
  return 0;
}
