#include <bits/stdc++.h>
using namespace std;
int n, m;
int read() {
  char ch = getchar();
  long long x = 0, f = 1;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + (ch - '0');
  return x * f;
}
int head[5010];
struct eto {
  int y, v, nxt;
} e[100100];
int tot = 0;
void add(int x, int y, int v) {
  e[++tot].y = y;
  e[tot].v = v;
  e[tot].nxt = head[x];
  head[x] = tot;
}
int x[5010], y[5010], z[5010];
int f[5010], qaq;
void dfs1(int x, int fa) {
  f[x] = 1;
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].y, v = e[i].v;
    if (y != fa) {
      dfs1(y, x);
      f[x] += f[y];
    }
  }
}
int sa, asd;
void dfs2(int x, int fa) {
  int wasd = qaq - f[x];
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].y, v = e[i].v;
    if (y != fa) {
      wasd = max(wasd, f[y]);
      dfs2(y, x);
    }
  }
  if (asd > wasd) asd = wasd, sa = x;
}
long long ans = 0;
int siz[5010];
void dfs_ans(int x, int fa) {
  siz[x] = 1;
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].y, v = e[i].v;
    if (y != fa) {
      dfs_ans(y, x);
      siz[x] += siz[y];
    }
  }
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].y, v = e[i].v;
    if (y != fa) ans += 1ll * v * (n - siz[y]) * siz[y];
  }
}
int main() {
  n = read();
  long long Ans = (1ll << 60);
  for (int i = 1; i < n; i++) {
    x[i] = read();
    y[i] = read();
    z[i] = read();
  }
  for (int i = 1; i < n; i++) {
    tot = 0;
    memset(f, 0, sizeof(f));
    memset(head, 0, sizeof(head));
    for (int j = 1; j < n; j++)
      if (j != i) {
        add(x[j], y[j], z[j]);
        add(y[j], x[j], z[j]);
      }
    asd = (1 << 30);
    dfs1(x[i], 0);
    qaq = f[x[i]];
    dfs2(x[i], 0);
    int t1 = sa;
    asd = (1 << 30);
    dfs1(y[i], 0);
    qaq = f[y[i]];
    dfs2(y[i], 0);
    int t2 = sa;
    add(t1, t2, z[i]);
    add(t2, t1, z[i]);
    ans = 0;
    dfs_ans(1, 0);
    Ans = min(Ans, ans);
  }
  printf("%lld", Ans);
  return 0;
}
