#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1073741824")
#pragma warning(disable : 4996)
using namespace std;
const int N = 5010;
const long long int INF = 4e18;
int a[N], b[N], w[N], sz[N];
bool ban[N];
vector<pair<int, int>> v[N];
long long int mn = 4e18, gl = 0;
void ctSz(int node, int par) {
  sz[node] = 1;
  for (auto p : v[node]) {
    if (p.first != par && !ban[p.second]) {
      ctSz(p.first, node);
      sz[node] += sz[p.first];
    }
  }
}
long long int ctGl(int node, int par, int s) {
  long long int r = 0;
  for (auto p : v[node]) {
    if (p.first != par && !ban[p.second]) {
      int ns = s + sz[node] - sz[p.first];
      r += ns * (long long int)sz[p.first] * w[p.second] +
           ctGl(p.first, node, ns);
    }
  }
  return r;
}
void dfs(int node, int par, int s, int oth) {
  mn = min(gl, mn);
  s++;
  for (auto p : v[node]) {
    int to = p.first, id = p.second;
    if (to != par && !ban[id]) {
      long long int was = gl;
      long long int ns = s + sz[node] - sz[to] - 1;
      gl += ns * (sz[to] + oth) * w[id] - (ns + oth) * sz[to] * w[id];
      dfs(to, node, ns, oth);
      gl = was;
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d%d", &a[i], &b[i], &w[i]);
    v[a[i]].push_back({b[i], i});
    v[b[i]].push_back({a[i], i});
  }
  long long int ans = INF;
  for (int i = 0; i < n - 1; i++) {
    ban[i] = 1;
    long long int cur = 0;
    ctSz(a[i], -1);
    ctSz(b[i], -1);
    mn = INF;
    gl = ctGl(a[i], -1, sz[b[i]]);
    dfs(a[i], -1, 0, sz[b[i]]);
    cur += mn;
    mn = INF;
    gl = ctGl(b[i], -1, sz[a[i]]);
    dfs(b[i], -1, 0, sz[a[i]]);
    cur += mn;
    cur += sz[a[i]] * (long long int)sz[b[i]] * w[i];
    ans = min(ans, cur);
    ban[i] = 0;
  }
  printf("%lld", ans);
  return 0;
}
