#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long, long long>>> g;
long long dfs(long long u, long long p) {
  long long ans = 0;
  for (long long i = 0; i < g[u].size(); i++) {
    long long to = g[u][i].first;
    long long w = g[u][i].second;
    if (to != p) {
      ans = max(ans, w + dfs(to, u));
    }
  }
  return ans;
}
int main() {
  long long n;
  cin >> n;
  g = vector<vector<pair<long long, long long>>>(n);
  long long u, v, w;
  for (long long i = 0; i < n - 1; i++) {
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  cout << dfs(0, -1) << endl;
}
