#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, inf = 1e9 + 10;
int n, ans;
vector<pair<int, int>> g[maxn];
void dfs(int u, int nxt, int par) {
  if (u == 1 && nxt == -1) return;
  if (nxt > 0) {
    for (auto i : g[u]) {
      int v = i.first, w = i.second;
      if (v == nxt) {
        ans += w;
        dfs(v, -1, u);
      }
    }
  } else {
    for (auto i : g[u]) {
      int v = i.first, w = i.second;
      if (v != par) {
        ans += w;
        dfs(v, -1, u);
      }
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back({b, 0});
    g[b].push_back({a, c});
  }
  dfs(1, g[1][0].first, -1);
  int out = ans;
  ans = 0;
  dfs(1, g[1][1].first, -1);
  cout << min(ans, out) << '\n';
  return 0;
}
