#include <bits/stdc++.h>
using namespace std;
const long long N = 5005;
long long a[N], b[N], w[N], sz[N], lsum[N];
vector<long long> adj[N];
void dfs(long long u, long long p, long long r, long long l) {
  sz[u] = 1;
  lsum[u] = l;
  for (long long j : adj[u])
    if (r ^ j && p ^ a[j] ^ b[j] ^ u) {
      long long v = a[j] ^ b[j] ^ u;
      dfs(v, u, r, l + w[j]);
      sz[u] += sz[v];
      lsum[u] += lsum[v];
    }
}
long long dfs(long long u, long long p, long long r, long long &s,
              long long tot, long long x) {
  long long res = x;
  for (long long j : adj[u])
    if (r ^ j && p ^ a[j] ^ b[j] ^ u) {
      long long v = a[j] ^ b[j] ^ u;
      s += w[j] * sz[v] * (tot - sz[v]);
      res = min(res, dfs(v, u, r, s, tot, x + (tot - 2 * sz[v]) * w[j]));
    }
  return res;
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i < n; i++) {
    cin >> a[i] >> b[i] >> w[i];
    adj[a[i]].push_back(i);
    adj[b[i]].push_back(i);
  }
  long long ans = 1e18;
  for (long long i = 1; i < n; i++) {
    dfs(a[i], 0, i, 0);
    dfs(b[i], 0, i, 0);
    long long k = sz[a[i]] * sz[b[i]] * w[i];
    long long x = dfs(a[i], 0, i, k, sz[a[i]], lsum[a[i]]);
    long long y = dfs(b[i], 0, i, k, sz[b[i]], lsum[b[i]]);
    k += sz[a[i]] * y + sz[b[i]] * x;
    ans = min(ans, k);
  }
  cout << ans << endl;
}
