#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
vector<pair<int, int> > g[5010];
int u[5010], v[5010], w[5010];
long long d[5010], sum, minn, ans;
long long son[5010];
void dfs(int u, int rt) {
  son[u] = 1;
  d[u] = 0;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    long long w = g[u][i].second;
    if (v == rt) continue;
    dfs(v, u);
    son[u] += son[v];
    d[u] += d[v] + w * son[v];
  }
}
void dfs2(int u, int fa, int rt) {
  minn = min(minn, d[u]);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    long long w = g[u][i].second;
    if (v == fa) continue;
    sum += w * (son[rt] - son[v]) * son[v];
    long long tmp = d[u] - w * son[v] - d[v];
    d[v] += tmp + w * (son[rt] - son[v]);
    dfs2(v, u, rt);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) g[i].clear();
  memset(d, 0, sizeof(d));
  memset(son, 0, sizeof(son));
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &u[i], &v[i], &w[i]);
    g[u[i]].push_back(make_pair(v[i], w[i]));
    g[v[i]].push_back(make_pair(u[i], w[i]));
  }
  int first, second, z;
  ans = INF;
  for (int i = 1; i < n; i++) {
    first = u[i], second = v[i], z = w[i];
    sum = 0;
    minn = INF;
    dfs(first, second);
    dfs2(first, second, first);
    sum += minn * (n - son[first]);
    minn = INF;
    dfs(second, first);
    dfs2(second, first, second);
    sum += minn * (n - son[second]);
    sum += z * son[first] * son[second];
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
