#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > v[100005];
stack<pair<int, int> > q;
bool vis[100005];
long long ans;
int k, par[100005], child;
void dfs(int j, long long int wt) {
  vis[j] = true;
  if (v[j].size() == 1 && vis[v[j][0].first]) {
    if (wt > ans) {
      ans = wt;
      child = j;
    }
    return;
  }
  for (int i = 0; i < v[j].size(); i++) {
    if (!vis[v[j][i].first]) {
      par[v[j][i].first] = j;
      dfs(v[j][i].first, wt + v[j][i].second);
    }
  }
}
int main() {
  int a, b, w;
  cin >> n;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b >> w;
    v[a].push_back({b, w});
    v[b].push_back({a, w});
  }
  memset(vis, false, sizeof(vis));
  ans = 0;
  child = 1;
  dfs(1, 0);
  memset(vis, false, sizeof(vis));
  vis[1] = true;
  while (child != 1) {
    vis[child] = true;
    child = par[child];
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      for (int j = 0; j < v[i].size(); j++) {
        if (v[i][j].first == par[i]) {
          ans += (v[i][j].second * 2);
          break;
        }
      }
    }
  }
  cout << ans;
}
