#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
struct Edge {
  int v, w, ne;
};
Edge e[MAXN * 2];
int hh[MAXN], ecnt;
long long Ans, tAns;
void addEdge(int u, int v, int w) {
  e[ecnt].v = v;
  e[ecnt].w = w;
  e[ecnt].ne = hh[u];
  hh[u] = ecnt++;
}
int n, cnt[MAXN], fa[MAXN];
int dfs1(int u, int pu) {
  int tmp = 1;
  fa[u] = pu;
  for (int i = hh[u]; i != -1; i = e[i].ne) {
    int v = e[i].v;
    if (v == pu) continue;
    int x = dfs1(v, u);
    Ans += (long long)x * (n - x) * e[i].w;
    tmp += x;
  }
  return cnt[u] = tmp;
}
pair<long long, int> dfs2(int u, int pu, int err, int add) {
  int tmp = 1;
  long long x = 0;
  for (int i = hh[u]; i != -1; i = e[i].ne) {
    int v = e[i].v;
    if (v == pu || v == err) continue;
    pair<long long, int> ans = dfs2(v, u, err, add);
    tmp += ans.second;
    long long xx =
        (long long)ans.second * e[i].w * (n - ans.second) -
        (long long)(ans.second + add) * e[i].w * (n - ans.second - add);
    if (ans.first > 0)
      x = max(x, ans.first + xx);
    else
      x = max(x, xx);
  }
  tAns = max(tAns, x);
  return make_pair(x, tmp);
}
int main() {
  scanf("%d", &n);
  memset(hh, -1, sizeof(int) * n);
  ecnt = 0;
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--;
    v--;
    addEdge(u, v, w);
    addEdge(v, u, w);
  }
  Ans = 0;
  dfs1(0, -1);
  long long maxx = Ans;
  for (int i = 0; i < n; i++) {
    long long pre = Ans;
    int u = i, v = fa[i];
    if (v == -1) continue;
    tAns = 0;
    dfs2(u, -1, v, n - cnt[u]);
    Ans -= tAns;
    tAns = 0;
    dfs2(v, -1, u, cnt[u]);
    Ans -= tAns;
    maxx = min(maxx, Ans);
    Ans = pre;
  }
  printf("%I64d\n", maxx);
  return 0;
}
