#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
vector<pair<int, int> > a[N];
long long s[N], c[N], sv[N], ss[N], ssum[N];
int fx, fy;
void go(int x, int from = -1) {
  c[x] = 1;
  s[x] = 0;
  for (typeof((a[x]).begin()) it = (a[x]).begin(); it != (a[x]).end(); it++) {
    if (it->first != from) {
      go(it->first, x);
      c[x] += c[it->first];
      s[x] += (it->second) * c[it->first] + s[it->first];
    }
  }
}
long long ans = (1LL << 60);
void go2(int x, int from = -1, long long S = 0, long long C = 0) {
  s[x] += S;
  sv[x] = s[x];
  ss[x] = s[x];
  for (typeof((a[x]).begin()) it = (a[x]).begin(); it != (a[x]).end(); it++) {
    if (it->first != from) {
      go2(it->first, x,
          s[x] - s[it->first] - (it->second) * (c[it->first]) +
              (it->second) * (C + c[x] - c[it->first]),
          C + c[x] - c[it->first]);
      sv[x] = min(sv[x], sv[it->first]);
      ss[x] += ss[it->first];
    }
  }
}
int e[N][3];
int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    if (x > y) swap(x, y);
    a[x].push_back(make_pair(y, w));
    a[y].push_back(make_pair(x, w));
    e[i][0] = x;
    e[i][1] = y;
    e[i][2] = w;
  }
  for (int i = 1; i < n; i++) {
    fx = e[i][0];
    fy = e[i][1];
    go(fx, fy);
    go(fy, fx);
    go2(fx, fy);
    go2(fy, fx);
    long long R = c[fx] * sv[fy] + e[i][2] * c[fx] * c[fy] + c[fy] * sv[fx] +
                  ss[fx] / 2 + ss[fy] / 2;
    ans = min(R, ans);
  }
  cout << ans;
  return 0;
}
