#include <bits/stdc++.h>
using namespace std;
long long temp = 0, r, l, z, w, k = 0, m1, e, p, q, k1 = 0, k2 = 0, d = 0,
          a = 0, b = 0, s = 0, x, y, min1 = 1000000010, max1 = 0, m = 0, c = 0,
          t = 0, i, n, c1 = 0, tot = 0, t1, k4 = 0, c2 = 0, j = 0, k3 = 0;
char ch, ch1, ch2;
string s2, s3;
const long long N = 5000010;
vector<pair<long long, long long> > graph[N];
long long vis[N];
vector<long long> v1;
long long dfs(long long k) {
  vis[k] = 1;
  long long ans = 0;
  for (auto it : graph[k]) {
    if (!vis[it.first]) ans = max(ans, dfs(it.first) + it.second);
  }
  return ans;
}
signed main() {
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    cin >> a >> b >> c;
    graph[a].push_back({b, c});
    graph[b].push_back({a, c});
  }
  cout << dfs(0);
}
