#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
vector<pair<long long, long long> > g[N];
int n, dp[N];
int col[N], u[N];
queue<int> q;
int mx = 0;
void bfs(int v, int p) {
  u[v] = 1;
  for (pair<long long, long long> to : g[v]) {
    if (to.first == p) continue;
    dp[to.first] = dp[v] + to.second;
    mx = max(mx, dp[to.first]);
    bfs(to.first, v);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    g[u].push_back({v, c});
    g[v].push_back({u, c});
  }
  bfs(0, 0);
  cout << mx;
  return 0;
}
