#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[100], b[100], c[100], total = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    --a[i];
    --b[i];
    total += c[i];
  }
  bool visited[n + 1];
  fill(visited, visited + n, false);
  int pos = 0, ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (a[j] == pos && !visited[j]) {
        ans += c[j];
        pos = b[j];
        visited[j] = true;
        break;
      } else if (b[j] == pos && !visited[j]) {
        pos = a[j];
        visited[j] = true;
        break;
      }
    }
  }
  ans = min(ans, total - ans);
  printf("%d\n", ans);
  return 0;
}
