#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
int n, bj;
vector<pair<int, int> > p[N];
pair<int, int> t[N];
long long res[N];
int son[N], sum, col[N], le[N];
int dfs(int x, int pre) {
  int sz = p[x].size(), cnt;
  res[x] = son[x] = 0;
  col[x] = bj;
  ++sum;
  for (int i = 0; i < (sz); ++i) {
    if (p[x][i].first != pre) {
      cnt = dfs(p[x][i].first, x);
      res[x] += p[x][i].second * 1LL * cnt;
      res[x] += res[p[x][i].first];
      son[x] += cnt;
    }
  }
  return son[x] + 1;
}
void dfs2(int x, int pre) {
  int sz = p[x].size();
  for (int i = 0; i < (sz); ++i) {
    if (p[x][i].first != pre) {
      res[p[x][i].first] =
          res[x] - (son[p[x][i].first] * 2 + 2 - sum) * 1LL * p[x][i].second;
      dfs2(p[x][i].first, x);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < (n - 1); ++i) {
    int x, y, d;
    cin >> x >> y >> d;
    --x, --y;
    p[x].push_back(make_pair(y, d));
    p[y].push_back(make_pair(x, d));
    t[i] = make_pair(x, y);
    le[i] = d;
  }
  long long ret = 1LL << 60;
  for (int i = 0; i < (n - 1); ++i) {
    sum = 0;
    bj = 1;
    dfs(t[i].first, t[i].second);
    dfs2(t[i].first, t[i].second);
    sum = 0;
    bj = 2;
    dfs(t[i].second, t[i].first);
    dfs2(t[i].second, t[i].first);
    long long t1 = 0, t2 = 0, s1 = 0, s2 = 0, m1 = 1LL << 60, m2 = 1LL << 60;
    for (int j = 0; j < (n); ++j) {
      if (col[j] == 1) {
        s1 += res[j];
        ++t1;
        m1 = min(m1, res[j]);
      } else {
        s2 += res[j];
        ++t2;
        m2 = min(m2, res[j]);
      }
    }
    ret = min(ret, (s1 + s2) / 2 + m1 * t2 + m2 * t1 + le[i] * 1LL * t1 * t2);
  }
  cout << ret << endl;
  return 0;
}
