#include <bits/stdc++.h>
using namespace std;
bool bo1[109], bo2[109];
int a[109][109], i, j, n, x, y, z;
int dfs1(int i, int x) {
  if (bo1[i]) return 0;
  bo1[i] = 1;
  for (j = 1; j <= n; j++)
    if (a[i][j] && j != x) {
      if (a[i][j] > 0) return a[i][j] + dfs1(j, i);
      return dfs1(j, i);
    }
  return 0;
}
int dfs2(int i, int x) {
  if (bo2[i]) return 0;
  bo2[i] = 1;
  for (j = n; j >= 1; j--)
    if (a[i][j] && j != x) {
      if (a[i][j] > 0) return a[i][j] + dfs2(j, i);
      return dfs2(j, i);
    }
  return 0;
}
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> y >> z;
    a[x][y] = -z;
    a[y][x] = z;
  }
  cout << min(dfs1(1, 0), dfs2(1, 0));
  return 0;
}
