#include <bits/stdc++.h>
using namespace std;
int i, j, k;
int w[110][110], e[110];
int main(void) {
  int n, a, b, c, ans = 0, sum = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a >> b >> c;
    sum += c;
    w[b][a] = c;
    e[a] ^= b;
    e[b] ^= a;
  }
  e[b] ^= a;
  for (i = b; e[i]; i = e[i]) {
    ans += w[i][e[i]];
    e[e[i]] ^= i;
  }
  cout << min(ans, sum - ans);
  return 0;
}
