#include <bits/stdc++.h>
using namespace std;
long long ans = 0x3f3f3f3f3f3f3f3f;
long long a, b;
int aa, bb;
struct edge {
  int id;
  long long w;
  edge *next;
};
edge edges[5050 << 1];
edge *adj[5050];
int ednum, siz[5050], dep[5050], bian1[5050], bian2[5050];
long long ww[5050];
long long dp[5050], rel[5050], ddp[5050], mine[5050];
inline void add_Edge(int a, int b, long long w) {
  edge *tmp = &edges[ednum++];
  tmp->id = b;
  tmp->w = w;
  tmp->next = adj[a];
  adj[a] = tmp;
}
int n;
void dfs(int pos, int deep) {
  dep[pos] = deep;
  siz[pos] = 1;
  mine[pos] = 0;
  dp[pos] = 0;
  for (edge *it = adj[pos]; it; it = it->next) {
    if (!dep[it->id]) {
      dfs(it->id, deep + 1);
      siz[pos] += siz[it->id];
      dp[pos] += it->w * siz[it->id] + dp[it->id];
      mine[pos] += siz[it->id] * it->w + dp[it->id];
    }
  }
}
void dfs3(int pos, int fa) {
  ddp[pos] = 0;
  a = a > rel[pos] + dp[pos] ? rel[pos] + dp[pos] : a;
  for (edge *it = adj[pos]; it; it = it->next) {
    if (dep[it->id] > dep[pos]) {
      long long tmp = mine[pos] - dp[it->id] - it->w * siz[it->id];
      rel[it->id] = rel[pos] + tmp;
      rel[it->id] += it->w * (siz[fa] - siz[it->id]);
      dfs3(it->id, fa);
      ddp[pos] += it->w * (siz[fa] - siz[it->id]) * siz[it->id] + ddp[it->id];
    }
  }
  dep[pos] = 0;
}
void dfs4(int pos, int fa) {
  ddp[pos] = 0;
  b = b > rel[pos] + dp[pos] ? rel[pos] + dp[pos] : b;
  for (edge *it = adj[pos]; it; it = it->next) {
    if (dep[it->id] > dep[pos]) {
      long long tmp = mine[pos] - dp[it->id] - it->w * siz[it->id];
      rel[it->id] = rel[pos] + tmp;
      rel[it->id] += it->w * (siz[fa] - siz[it->id]);
      dfs4(it->id, fa);
      ddp[pos] += it->w * (siz[fa] - siz[it->id]) * siz[it->id] + ddp[it->id];
    }
  }
  dep[pos] = 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    long long w;
    scanf("%d%d%I64d", &a, &b, &w);
    add_Edge(a, b, w);
    add_Edge(b, a, w);
    bian1[i] = a;
    bian2[i] = b;
    ww[i] = w;
  }
  long long tmp;
  for (int i = 1; i < n; i++) {
    memset(dep, 0, sizeof(dep));
    aa = bian1[i];
    bb = bian2[i];
    dep[aa] = 1;
    dep[bb] = 1;
    dfs(aa, 1);
    dfs(bb, 1);
    b = a = 0x3f3f3f3f3f3f3f3f;
    rel[aa] = 0;
    rel[bb] = 0;
    dfs3(aa, aa);
    dfs4(bb, bb);
    tmp = a * siz[bb] + b * siz[aa] + ww[i] * siz[aa] * siz[bb] + ddp[aa] +
          ddp[bb];
    ans = ans < tmp ? ans : tmp;
  }
  printf("%I64d\n", ans);
}
