#include <bits/stdc++.h>
using namespace std;
const long long maxx = 5005, inf = 1e18;
bool vis[maxx];
pair<long long, long long> dp1[maxx], dp2[maxx], edge[maxx];
vector<pair<long long, long long> > adj[maxx];
long long markaz, m1, m2, dpm, w = inf, n;
void dfs1(long long root, long long yal) {
  vis[root] = true;
  dp1[root] = make_pair(0, 1);
  for (pair<long long, long long> x : adj[root]) {
    if (!vis[x.first] && (make_pair(x.first, root) != edge[yal]) &&
        (make_pair(root, x.first) != edge[yal])) {
      dfs1(x.first, yal);
      dp1[root].first += dp1[x.first].first + (dp1[x.first].second * x.second);
      dp1[root].second += dp1[x.first].second;
    }
  }
}
void dfs2(long long root, long long par, long long len, long long yal) {
  vis[root] = true;
  if (par == -1) dp2[root] = make_pair(0, 1);
  for (pair<long long, long long> x : adj[root]) {
    if (!vis[x.first] && (make_pair(x.first, root) != edge[yal]) &&
        (make_pair(root, x.first) != edge[yal])) {
      dp2[x.first].second =
          dp2[root].second + dp1[root].second - dp1[x.first].second;
      dp2[x.first].first =
          dp1[root].first -
          (dp1[x.first].first + (x.second * dp1[x.first].second)) +
          dp2[root].first + ((dp2[x.first].second - 1) * x.second);
      dfs2(x.first, root, x.second, yal);
    }
  }
}
void dfs3(long long root, long long yal) {
  vis[root] = true;
  if (dp1[root].first + dp2[root].first < dpm) {
    dpm = dp1[root].first + dp2[root].first;
    markaz = root;
  }
  for (pair<long long, long long> x : adj[root]) {
    if (!vis[x.first] && (make_pair(x.first, root) != edge[yal]) &&
        (make_pair(root, x.first) != edge[yal]))
      dfs3(x.first, yal);
  }
}
long long f(long long i) {
  long long x1 = edge[i].first, y1 = edge[i].second, x2, y2;
  fill(vis, vis + maxx, false);
  dfs1(x1, i);
  dfs1(y1, i);
  fill(vis, vis + maxx, false);
  dfs2(x1, -1, -1, i);
  dfs2(y1, -1, -1, i);
  fill(vis, vis + maxx, false);
  dpm = inf;
  dfs3(x1, i);
  x2 = markaz;
  dpm = inf;
  dfs3(y1, i);
  y2 = markaz;
  long long t1 = dp1[x1].second + dp2[x1].second - 1,
            t2 = dp1[y1].second + dp2[y1].second - 1;
  return (w -
          (t2 * (max(0ll, (dp1[x1].first + dp2[x1].first) -
                              (dp1[x2].first + dp2[x2].first)))) -
          (t1 * (max(0ll, (dp1[y1].first + dp2[y1].first) -
                              (dp1[y2].first + dp2[y2].first)))));
}
int main() {
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    adj[a].push_back(make_pair(b, c));
    adj[b].push_back(make_pair(a, c));
    edge[i] = make_pair(a, b);
  }
  edge[n] = make_pair(-1, -1);
  w = 0;
  fill(vis, vis + maxx, false);
  dfs1(0, n);
  fill(vis, vis + maxx, false);
  dfs2(0, -1, -1, n);
  for (long long i = 0; i < n; i++) w += (dp1[i].first + dp2[i].first);
  w /= 2;
  long long ans = inf;
  for (long long i = 0; i < n - 1; i++) ans = min(ans, f(i));
  cout << ans << endl;
  return 0;
}
