#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
inline long long getnum() {
  char c = getchar();
  long long num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
inline long long power(long long a, long long b) {
  long long multiply = 1;
  for (int i = (0); i < (b); i++) {
    multiply *= a;
  }
  return multiply;
}
int n, k, u, v, w, weight[100002];
vector<pair<int, int>> graph[100002];
long long dp[100002][2];
void dfs(int u, int p) {
  for (auto it : graph[u]) {
    int v = it.first, c = it.second;
    if (v == p) continue;
    weight[v] = c;
    dfs(v, u);
  }
}
void solve(int u, int p) {
  dp[u][0] = weight[u];
  dp[u][1] = weight[u];
  vector<pair<long long, int>> esc, desc;
  for (auto it : graph[u]) {
    int v = it.first;
    if (v == p) continue;
    solve(v, u);
    esc.push_back({-dp[v][1], v});
    desc.push_back({-dp[v][0], v});
  }
  sort(esc.begin(), esc.end());
  sort(desc.begin(), desc.end());
  vector<int> chosen;
  for (int i = (0); i < (min(k - 1, (int)esc.size())); i++) {
    dp[u][1] += esc[i].first * (-1);
    chosen.push_back(esc[i].second);
  }
  sort(chosen.begin(), chosen.end());
  long long add = 0;
  for (int i = (0); i < (desc.size()); i++) {
    long long t = dp[u][1] - weight[u];
    if (binary_search(chosen.begin(), chosen.end(), desc[i].second)) {
      t -= dp[desc[i].second][1];
      t += desc[i].first * -1;
      if (k <= esc.size()) t += esc[k - 1].first * -1;
    } else {
      t += desc[i].first * -1;
    }
    add = max(add, t);
  }
  dp[u][0] += add;
}
int main() {
  int test, cases = 1;
  scanf("%d", &n);
  k = 1;
  for (int i = (0); i < (n - 1); i++) {
    scanf("%d%d%d", &u, &v, &w);
    graph[u].push_back({v, w});
    graph[v].push_back({u, w});
  }
  dfs(0, -1);
  solve(0, -1);
  cout << max(dp[0][0], dp[0][1]) << "\n";
  return 0;
}
