#include <bits/stdc++.h>
using namespace std;
void solve();
const int MAX_N = 101;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const long long LINF = 1ll * 1000000 * 1000000 * 1000000;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  for (int i = 0; i < t; ++i) {
    solve();
    cout << "\n";
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs"
       << "\n";
  return 0;
}
void solve() {
  int n;
  cin >> n;
  set<int> start, end;
  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    if (start.find(b) != start.end() or end.find(a) != end.end()) {
      start.insert(a);
      end.insert(b);
      ans1 += c;
    } else {
      start.insert(b);
      end.insert(a);
      ans2 += c;
    }
  }
  cout << min(ans1, ans2);
}
