#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 100;
vector<pair<int, int> > adj[maxn];
vector<pair<pair<int, int>, long long int> > e;
long long int n, m, comp, Ver[2];
long long int dp[maxn], pd[maxn], T[maxn], dis[maxn], c[maxn];
bool mark[maxn];
void dfs(int v) {
  T[v]++;
  c[v] = comp;
  mark[v] = true;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i].first;
    int w = adj[v][i].second;
    if (!mark[u]) {
      dfs(u);
      T[v] += T[u];
      dp[v] += dp[u] + T[u] * w;
    }
  }
}
void dfs2(int v) {
  mark[v] = true;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i].first;
    int w = adj[v][i].second;
    if (!mark[u]) {
      pd[u] += (m - T[u]) * w + pd[v] + dp[v] - (dp[u] + T[u] * w);
      dfs2(u);
    }
  }
}
void Update() {
  memset(mark, false, sizeof mark);
  memset(dp, 0, sizeof dp);
  memset(pd, 0, sizeof pd);
  memset(T, 0, sizeof T);
  comp = 0;
  for (int i = 0; i < n; i++)
    if (!mark[i]) dfs(i), comp++;
  int com = 0;
  for (int i = 0; i < n; i++)
    if (c[i] == 0) com++;
  memset(mark, false, sizeof mark);
  for (int i = 0; i < n; i++)
    if (!mark[i]) {
      m = (c[i] == 0 ? com : n - com);
      Ver[c[i]] = m;
      dfs2(i);
    }
  for (int i = 0; i < n; i++) dis[i] = dp[i] + pd[i];
}
void del(int v, int u) {
  vector<pair<int, int> > ver;
  for (int i = 0; i < adj[v].size(); i++)
    if (adj[v][i].first == u) adj[v].erase(adj[v].begin() + i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int v, u, w;
    cin >> v >> u >> w;
    v--, u--;
    adj[v].push_back(make_pair(u, w));
    adj[u].push_back(make_pair(v, w));
    e.push_back(make_pair(make_pair(v, u), w));
  }
  long long int ans = 1e18;
  for (int p = 0; p < n - 1; p++) {
    int v = e[p].first.first, u = e[p].first.second, w = e[p].second;
    del(v, u), del(u, v);
    Update();
    int V = -1, U = -1;
    for (int i = 0; i < n; i++) {
      if (c[i] == 0 and (V == -1 or dis[i] < dis[V])) V = i;
      if (c[i] == 1 and (U == -1 or dis[i] < dis[U])) U = i;
    }
    long long int Sum = 0;
    for (int i = 0; i < n; i++) Sum += dis[i];
    Sum /= 2;
    Sum += w * Ver[0] * Ver[1];
    Sum += dis[V] * Ver[c[U]];
    Sum += dis[U] * Ver[c[V]];
    ans = min(ans, Sum);
    adj[v].push_back(make_pair(u, w));
    adj[u].push_back(make_pair(v, w));
  }
  cout << ans << endl;
  return 0;
}
