#include <bits/stdc++.h>
int edge[110][110];
bool flag[110];
int main() {
  memset(edge, 0, sizeof(edge));
  int i, j;
  int n;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    edge[x][y] = c;
    edge[y][x] = -c;
  }
  int min = 100000000;
  int s = 0;
  for (i = 1; i <= n; i++) {
    if (edge[1][i] != 0) {
      s = 0;
      int x = i;
      int front = 1;
      if (edge[1][i] < 0) s += -edge[1][i];
      while (x != 1) {
        for (j = 1; j <= n; j++) {
          if (edge[x][j] != 0 && j != front) {
            if (edge[x][j] < 0) s += -edge[x][j];
            front = x;
            x = j;
            break;
          }
        }
      }
      if (min > s) min = s;
    }
  }
  printf("%d\n", min);
  return 0;
}
