#include <bits/stdc++.h>
using namespace std;
const int maxN = 5000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
long long d[maxN], dpar[maxN], cnt[maxN];
int comp[3];
vector<pair<int, int> > adj[maxN];
int mark[maxN];
pair<int, int> cut;
void dfs1(int x, int c) {
  mark[x] = c;
  comp[c]++;
  cnt[x] = 1;
  for (int i = 0; i < ((int)(adj[x]).size()); i++) {
    int u = adj[x][i].first;
    long long w = adj[x][i].second;
    if (mark[u] || make_pair(u, x) == cut || make_pair(x, u) == cut) continue;
    dfs1(u, c);
    cnt[x] += cnt[u];
    d[x] += d[u] + cnt[u] * w;
  }
}
void dfs2(int x, int c) {
  mark[x] = c;
  for (int i = 0; i < ((int)(adj[x]).size()); i++) {
    int u = adj[x][i].first;
    long long w = adj[x][i].second;
    if (mark[u] || make_pair(u, x) == cut || make_pair(x, u) == cut) continue;
    dpar[u] = dpar[x] + d[x] - (d[u] + cnt[u] * w) + (comp[c] - cnt[u]) * w;
    dfs2(u, c);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, int> > edge;
  vector<long long> we;
  for (int i = 0; i < n - 1; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    adj[u].push_back(make_pair(v, c));
    adj[v].push_back(make_pair(u, c));
    edge.push_back(make_pair(u, v));
    we.push_back(c);
  }
  long long ans = (1ll << 55);
  for (int j = 0; j < n - 1; j++) {
    cut = edge[j];
    for (int i = 0; i < n; i++) mark[i] = dpar[i] = d[i] = cnt[i] = 0;
    comp[1] = comp[2] = 0;
    int y = 1;
    for (int i = 0; i < n; i++)
      if (!mark[i]) dfs1(i, y++);
    memset(mark, 0, sizeof(mark));
    y = 1;
    for (int i = 0; i < n; i++)
      if (!mark[i]) dfs2(i, y++);
    long long m1, m2;
    m1 = m2 = (1ll << 55);
    for (int i = 0; i < n; i++) {
      if (mark[i] == 1)
        m1 = min(m1, d[i] + dpar[i]);
      else
        m2 = min(m2, d[i] + dpar[i]);
    }
    long long sum = 0;
    for (int i = 0; i < n; i++) sum += d[i] + dpar[i];
    sum /= 2;
    sum += (m1 * comp[2] + m2 * comp[1]) + comp[1] * comp[2] * we[j];
    ans = min(sum, ans);
  }
  cout << ans << endl;
  return 0;
}
