#include <bits/stdc++.h>
bool visit[105] = {0};
int road[105][105];
int n;
int min(int a, int b) { return (a < b) ? a : b; }
int dfs(int node);
int main() {
  scanf("%d", &n);
  int i, j;
  int a[105], b[105], c[105];
  for (i = 0; i < 105; i++) {
    for (j = 0; j < 105; j++) {
      road[i][j] = 2000000000;
    }
  }
  int sum = 0;
  for (i = 0; i < n; i++) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    road[a[i]][b[i]] = c[i];
    sum += c[i];
  }
  int x = dfs(1);
  printf("%d", min(x, sum - x));
  return 0;
}
int dfs(int node) {
  if (visit[node] && node == 1) return 0;
  visit[node] = 1;
  int i;
  for (i = 1; i <= n; i++) {
    if (road[node][i] != 2000000000) {
      road[node][i] = 2000000000;
      return dfs(i);
    }
  }
  int k;
  for (i = 1; i <= n; i++) {
    if (road[i][node] != 2000000000) {
      k = road[i][node];
      road[i][node] = 2000000000;
      return dfs(i) + k;
    }
  }
}
