#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void sc(T &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c<48 | c> 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
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);
}
const int N = 1e5 + 5;
vector<pair<int, int> > G[N];
int n;
long long ans = 0;
bool flag = 0;
int tot = 0;
pair<int, int> dir[N];
int dp[N];
void dfs(int u, int p) {
  int dist = 0;
  for (auto a : G[u])
    if (a.second != p) {
      dfs(a.second, u);
      int maxd = a.first + dp[a.second];
      if (dist < maxd) {
        dist = maxd;
        dir[u] = make_pair(a.second, a.first);
      }
    }
  dp[u] = dist;
}
void dfs1(int u, int p) {
  tot++;
  if (tot == n) {
    flag = 1;
    return;
  }
  for (auto a : G[u]) {
    if (a.second == p || a.second == dir[u].first) continue;
    ans += a.first;
    dfs1(a.second, u);
    if (!flag) ans += a.first;
  }
  if (dir[u].first > 0) {
    ans += dir[u].second;
    dfs1(dir[u].first, u);
    if (!flag) ans += dir[u].second;
  }
}
int main() {
  sc(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    sc(u);
    sc(v);
    sc(w);
    u--, v--;
    G[u].push_back((make_pair(w, v)));
    G[v].push_back((make_pair(w, u)));
  }
  for (int i = 0; i < n; i++) {
    sort((G[i]).begin(), (G[i]).end());
  }
  dfs(0, -1);
  dfs1(0, -1);
  cout << ans << endl;
}
