#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 12, big = 1e18, mod = 998244353;
const double pi = acos(-1);
long long n, x, y, z;
vector<pair<long long, long long> > a[N];
long long dfs(long long i, long long pa) {
  long long ans = 0;
  for (auto j : a[i])
    if (j.first != pa) ans = max(ans, dfs(j.first, i) + j.second);
  return ans;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++)
    cin >> x >> y >> z, a[x].push_back(make_pair(y, z)),
        a[y].push_back(make_pair(x, z));
  cout << dfs(0, -1);
}
