#include <bits/stdc++.h>
using namespace std;
vector<int> a, b, w;
vector<vector<int>> g;
vector<long long> sum;
vector<bool> used;
vector<long long> dst;
int k1;
long long dfs1(int v, int p = -1, long long d = 0) {
  if (p != -1) {
    dst[v] = d;
  }
  used[v] = true;
  long long ans = d;
  for (int e : g[v]) {
    int vv = b[e];
    if (!used[vv] && (p == -1 || (e != p && e != (p ^ 1)))) {
      ans += dfs1(vv, p, d + w[e]);
    }
  }
  return ans;
}
void dfs2(int v, int p) {
  used[v] = true;
  ++k1;
  for (int e : g[v]) {
    int vv = b[e];
    if (!used[vv] && e != p && e != (p ^ 1)) {
      dfs2(vv, p);
    }
  }
}
int main() {
  int n;
  cin >> n;
  int m = n - 1;
  a.resize(2 * m);
  b.resize(2 * m);
  w.resize(2 * m);
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    cin >> a[2 * i] >> b[2 * i] >> w[2 * i];
    --a[2 * i], --b[2 * i];
    a[2 * i + 1] = b[2 * i];
    b[2 * i + 1] = a[2 * i];
    w[2 * i + 1] = w[2 * i];
  }
  m *= 2;
  for (int i = 0; i < m; ++i) {
    g[a[i]].push_back(i);
  }
  sum.resize(n);
  long long ssum = 0;
  for (int i = 0; i < n; ++i) {
    used.assign(n, false);
    sum[i] = dfs1(i);
    ssum += sum[i];
  }
  long long ans = ssum / 2;
  for (int e = 0; e < m; e += 2) {
    dst.resize(n);
    used.assign(n, false);
    long long suma = dfs1(a[e], e, 0);
    long long sumb = dfs1(b[e], e, 0);
    k1 = 0;
    used.assign(n, false);
    dfs2(a[e], e);
    int k2 = n - k1;
    int tw = w[e];
    int m1 = -1, m2 = -1;
    long long s1 = 0, s2 = 0;
    for (int i = 0; i < n; ++i) {
      if (used[i]) {
        long long ts = sum[i] - sumb - (dst[i] + tw) * k2;
        if (m1 == -1 || ts < s1) {
          m1 = i;
          s1 = ts;
        }
      } else {
        long long ts = sum[i] - suma - (dst[i] + tw) * k1;
        if (m2 == -1 || ts < s2) {
          m2 = i;
          s2 = ts;
        }
      }
    }
    long long nsum = ssum / 2 - suma * k2 - sumb * k1 + s1 * k2 + s2 * k1;
    if (nsum < ans) {
      ans = nsum;
    }
  }
  cout << ans << endl;
  return 0;
}
