#include <bits/stdc++.h>
using namespace std;
const long long int inf = 2e5 + 5;
const long long int MOD = 1e9 + 7;
const int MAX = 2e5 + 2;
using namespace std;
int n;
vector<vector<pair<long long, long long>>> g;
long long ans = 0;
vector<bool> vis;
void dfs(long long i, long long sum) {
  vis[i] = true;
  ans = max(ans, sum);
  for (auto p : g[i]) {
    long long n2 = p.first;
    long long cost = p.second;
    if (!vis[n2]) {
      dfs(n2, sum + cost);
    }
  }
}
void solve() {
  cin >> n;
  g.resize(n + 1);
  vis.resize(n + 1, false);
  n--;
  while (n--) {
    long long n1, n2, cost;
    cin >> n1 >> n2 >> cost;
    g[n1].push_back({n2, cost});
    g[n2].push_back({n1, cost});
  }
  dfs(0ll, 0ll);
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
