#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6, OO = 1e14, MOD = 1e9 + 7;
const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};
long long TC, n, m, k, a, b, c, d, x, y, l, r, cnt, sum, mx, mn, arr[N];
vector<pair<long long, long long> > adj[N];
bool f, vis[N];
long long dfs(long long node = 0) {
  vis[node] = 1;
  long long ans = 0;
  for (auto it : adj[node]) {
    if (!vis[it.first]) ans = max(ans, it.second + dfs(it.first));
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    cin >> a >> b >> c;
    adj[a].emplace_back(b, c);
    adj[b].emplace_back(a, c);
  }
  cout << dfs();
  return 0;
}
