#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int a[n], b[n], c[n], i, j, k, m, fc = 0, s = 0, fc1 = 0;
  for (i = 0; i < n; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
  }
  m = b[0];
  fc1 = c[0];
  for (k = 0; k < n - 1; k++) {
    for (j = 0; j < n - 1; j++) {
      if (m == b[j + 1] && s != j + 1) {
        m = a[j + 1];
        fc = fc + c[j + 1];
        s = j + 1;
        break;
      }
      if (m == a[j + 1] && s != j + 1) {
        m = b[j + 1];
        s = j + 1;
        break;
      }
    }
    fc1 = fc1 + c[k + 1];
  }
  fc1 = fc1 - fc;
  if (fc1 > fc) {
    printf("%d", fc);
  } else {
    printf("%d", fc1);
  }
}
