#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<bool> a(n + 1, false);
  vector<bool> b(n + 1, false);
  int ans = 0;
  int t_cost = 0;
  for (int i = 0; i < n; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    t_cost += w;
    if (a[x] || b[y]) {
      ans += w;
      a[y] = true;
      b[x] = true;
    } else {
      a[x] = true;
      b[y] = true;
    }
  }
  ans = min(ans, t_cost - ans);
  cout << ans << endl;
  return 0;
}
