#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const long long INF = 1e18;
struct node {
  int u, v, w;
  node(int u = 0, int v = 0, int w = 0) : u(u), v(v), w(w) {}
} a[2 * N];
int fst[N], nxt[2 * N], tot, n, size[N];
bool vis[N];
long long ans, sum[N], ans0, mn;
void build(int x, int y, int z) {
  a[tot] = node(x, y, z);
  nxt[tot] = fst[x];
  fst[x] = tot++;
}
void calc(int x) {
  int y;
  size[x] = 1;
  for (int p = fst[x]; ~p; p = nxt[p]) {
    if (vis[p / 2]) continue;
    vis[p / 2] = 1;
    y = a[p].v;
    calc(y);
    size[x] += size[y];
    ans += (long long)a[p].w * size[y] * (n - size[y]);
  }
}
void dfs1(int x) {
  int y;
  sum[x] = 0;
  size[x] = 1;
  for (int p = fst[x]; ~p; p = nxt[p]) {
    if (vis[p / 2]) continue;
    vis[p / 2] = 1;
    y = a[p].v;
    dfs1(y);
    sum[x] = (long long)sum[y] + (long long)size[y] * a[p].w;
    size[x] += size[y];
  }
}
void dfs2(int x, int all) {
  int y;
  for (int p = fst[x]; ~p; p = nxt[p]) {
    if (vis[p / 2]) continue;
    vis[p / 2] = 1;
    y = a[p].v;
    sum[y] = sum[x] - (long long)size[y] * a[p].w +
             (long long)(all - size[y]) * a[p].w;
    mn = min(mn, sum[y]);
    dfs2(y, all);
  }
}
long long work(int x, int i) {
  for (int j = 0; j < n - 1; j++) vis[j] = i == j ? 1 : 0;
  dfs1(x);
  for (int j = 0; j < n - 1; j++) vis[j] = i == j ? 1 : 0;
  mn = sum[x];
  dfs2(x, size[x]);
  return (long long)(mn - sum[x]) * (n - size[x]);
}
int main() {
  int x, y, z;
  scanf("%d", &n);
  tot = 0;
  memset(fst, -1, sizeof(fst));
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d%d", &x, &y, &z);
    x--;
    y--;
    build(x, y, z);
    build(y, x, z);
  }
  ans = 0;
  calc(0);
  ans0 = ans;
  long long tmp;
  for (int i = 0; i < n - 1; i++) {
    tmp = ans0 + work(a[i * 2].u, i) + work(a[i * 2].v, i);
    ans = min(ans, tmp);
  }
  cout << ans << "\n";
  return 0;
}
