#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
const int maxn = 5010;
struct E {
  int v, next;
  long long w;
} e[maxn << 1];
int head[maxn], tot;
void add(int s, int t, long long w) {
  e[tot].v = t;
  e[tot].w = w;
  e[tot].next = head[s];
  head[s] = tot++;
  e[tot].v = s;
  e[tot].w = w;
  e[tot].next = head[t];
  head[t] = tot++;
}
void init() {
  tot = 0;
  memset(head, -1, sizeof(head));
}
int n;
long long sum;
long long ans, dp[maxn], mi;
int son[maxn];
void dfs(int u, int fa) {
  son[u] = 1;
  dp[u] = 0;
  int i;
  for (i = head[u]; ~i; i = e[i].next) {
    int v = e[i].v;
    if (v == fa) continue;
    dfs(v, u);
    son[u] += son[v];
    dp[u] += dp[v] + e[i].w * son[v];
  }
}
void dfs2(int u, int fa, int rt) {
  mi = min(mi, dp[u]);
  int i;
  for (i = head[u]; ~i; i = e[i].next) {
    int v = e[i].v;
    if (v == fa) continue;
    sum += e[i].w * (son[rt] - son[v]) * son[v];
    dp[v] = dp[u] - e[i].w * son[v] + e[i].w * (son[rt] - son[v]);
    dfs2(v, u, rt);
  }
}
int u[maxn], v[maxn];
long long w[maxn];
int main() {
  ios ::sync_with_stdio(0);
  int i, j;
  cin >> n;
  init();
  int x, y;
  long long z;
  for (i = 0; i < n - 1; i++) {
    cin >> u[i] >> v[i] >> w[i];
    add(u[i], v[i], w[i]);
  }
  ans = INF;
  for (i = 0; i < n - 1; i++) {
    x = u[i];
    y = v[i];
    z = w[i];
    sum = 0;
    mi = INF;
    dfs(x, y);
    dfs2(x, y, x);
    sum += mi * (n - son[x]);
    mi = INF;
    dfs(y, x);
    dfs2(y, x, y);
    sum += mi * (n - son[y]);
    sum += z * son[x] * son[y];
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
