#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> adj[100000];
vector<long long> visited(100000, false);
bool comp(const pair<long long, long long> &a,
          const pair<long long, long long> &b) {
  return (a.second < b.second);
}
long long c = 0;
long long dfs(long long s) {
  visited[s] = true;
  bool turu = true;
  long long paisa = 0;
  for (long long i = 0; i < adj[s].size(); i++) {
    if (!visited[adj[s][i].first]) {
      paisa = adj[s][i].second + dfs(adj[s][i].first);
      turu = false;
      break;
    }
  }
  if (turu) {
    for (long long i = 0; i < adj[s].size(); i++)
      if (adj[s][i].first == 1) paisa = adj[s][i].second;
  }
  return paisa;
}
void solve() {
  long long n;
  cin >> n;
  long long dd = 0;
  long long z = n;
  while (z--) {
    long long a, b, w;
    cin >> a >> b >> w;
    adj[a].push_back({b, 0});
    adj[b].push_back({a, w});
    dd += w;
  }
  long long paisa1 = dfs(1);
  long long paisa2 = dd - paisa1;
  cout << min(paisa1, paisa2);
}
signed main() {
  long long t = 1;
  while (t--) {
    solve();
    cout << endl;
  }
}
