#include <bits/stdc++.h>
using namespace std;
long long f[5555], dp[5555], g[5555];
int child[5555];
vector<vector<pair<int, int> > > adj;
int val[5555];
int V;
long long res2;
void pre(int u, int par, int ignore) {
  child[u] = 1;
  for (int i = 0, _n = adj[u].size(); i < _n; i++) {
    int v = adj[u][i].first;
    if (v == par || v == ignore) continue;
    pre(v, u, ignore);
    child[u] += child[v];
  }
}
void dfs(int s, int u, int par, int ignore) {
  for (int i = 0, _n = adj[u].size(); i < _n; i++) {
    int v = adj[u][i].first;
    int w = adj[u][i].second;
    if (v == par || v == ignore) continue;
    dfs(s, v, u, ignore);
    g[u] += g[v] + 1LL * w * child[v];
    dp[u] = dp[u] + dp[v] + 1LL * (child[s] - child[v]) * child[v] * w;
  }
}
void dfs2(int s, int u, int par, int ignore, int w) {
  if (par != 0) {
    f[u] = f[par] + g[par] - g[u] + 1LL * (child[s] - 2 * child[u]) * w;
    res2 = min(res2, f[u] + g[u]);
  }
  for (int i = 0, _n = adj[u].size(); i < _n; i++) {
    int v = adj[u][i].first;
    int z = adj[u][i].second;
    if (v == par || v == ignore) continue;
    dfs2(s, v, u, ignore, z);
  }
}
long long process(int s, int t) {
  memset(child, 0, sizeof child);
  memset(dp, 0, sizeof dp);
  memset(f, 0, sizeof f);
  memset(g, 0, sizeof g);
  pre(s, 0, t);
  dfs(s, s, 0, t);
  res2 = g[s];
  dfs2(s, s, 0, t, 0);
  return 1LL * res2 * (V - child[s]) + dp[s];
}
int main() {
  int u, v, w;
  vector<pair<int, int> > edge;
  long long res = 1LL * 1000000000 * 100000000;
  scanf("%d", &V);
  adj.assign(V + 1, vector<pair<int, int> >());
  for (int i = 0, _n = V - 1; i < _n; i++) {
    scanf("%d%d%d", &u, &v, &w);
    adj[u].push_back(pair<int, int>(v, w));
    adj[v].push_back(pair<int, int>(u, w));
    edge.push_back(pair<int, int>(u, v));
    val[i] = w;
  }
  for (int i = 0, _n = V - 1; i < _n; i++) {
    int u = edge[i].first, v = edge[i].second;
    long long tmp = 0;
    tmp += process(u, v);
    tmp += 1LL * child[u] * (V - child[u]) * val[i];
    tmp += process(v, u);
    res = min(res, tmp);
  }
  cout << res << endl;
  return 0;
}
