#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int N = 5e3 + 10;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long long inf = 8e18;
const int LOG = 22;
long long pw(long long a, long long b, long long M) {
  return (!b ? 1
             : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M
                      : pw(a * a % M, b / 2, M)));
}
struct edge {
  int a, b, w;
};
edge E[N];
int n, sub[N];
long long tot;
vector<int> G[N];
vector<pair<long long, long long> > adj[N];
void pre(int v, int P) {
  sub[v] = 1;
  for (auto u : G[v]) {
    if (u == P) continue;
    pre(u, v);
    sub[v] += sub[u];
  }
}
int centroid(int v, int P, int mol) {
  for (auto u : G[v]) {
    if (u == P) continue;
    if (sub[u] * 2 > mol) {
      return centroid(u, v, mol);
    }
  }
  return v;
}
void dfs(int v, int P) {
  sub[v] = 1;
  for (auto y : adj[v]) {
    long long u = y.first, cost = y.second;
    if (u == P) continue;
    dfs(u, v);
    sub[v] += sub[u];
    tot += cost * sub[u] * (n - sub[u]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &E[i].a, &E[i].b, &E[i].w);
  }
  long long ans = inf;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j <= n + 1; j++) adj[j].clear(), G[j].clear();
    for (int j = 1; j < n; j++) {
      if (i == j) continue;
      G[E[j].a].push_back(E[j].b);
      G[E[j].b].push_back(E[j].a);
      adj[E[j].a].push_back(make_pair(E[j].b, E[j].w));
      adj[E[j].b].push_back(make_pair(E[j].a, E[j].w));
    }
    pre(E[i].a, -1);
    pre(E[i].b, -1);
    int v = centroid(E[i].a, -1, sub[E[i].a]),
        u = centroid(E[i].b, -1, sub[E[i].b]);
    adj[v].push_back(make_pair(u, E[i].w));
    adj[u].push_back(make_pair(v, E[i].w));
    tot = 0;
    dfs(1, -1);
    ans = min(ans, tot);
  }
  printf("%lld", ans);
  return 0;
}
