#include <bits/stdc++.h>
using namespace std;
int matr[200][200];
int color[200];
int n, m;
int g;
int q;
int ans;
void dfs1(int x) {
  int i;
  q++;
  if (q == n) color[1] = 0;
  color[x] = 1;
  for (i = 1; i <= n; i++) {
    if (color[i]) continue;
    if (matr[x][i] != 0) {
      dfs1(i);
      return;
    } else if (matr[i][x] != 0) {
      g += matr[i][x];
      dfs1(i);
      return;
    }
  }
}
void dfs2(int x) {
  int i;
  q++;
  if (q == n) color[1] = 0;
  color[x] = 1;
  for (i = n; i >= 1; i--) {
    if (color[i]) continue;
    if (matr[x][i] != 0) {
      dfs2(i);
      return;
    } else if (matr[i][x] != 0) {
      g += matr[i][x];
      dfs2(i);
      return;
    }
  }
}
int main() {
  int a, b, c;
  int i;
  scanf("%d", &n);
  m = n;
  for (i = 1; i <= n; i++) {
    scanf("%d %d %d", &a, &b, &c);
    matr[a][b] = c;
  }
  memset(color, 0, sizeof(color));
  ;
  g = 0;
  q = 0;
  dfs1(1);
  ans = g;
  memset(color, 0, sizeof(color));
  ;
  g = 0;
  q = 0;
  dfs2(1);
  ans = min(ans, g);
  printf("%d\n", ans);
  return 0;
}
