#include <bits/stdc++.h>
using namespace std;
int N, a, b, c;
int path[105][105];
bool isVisited[105];
int totAll, totCc;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(path, -1, sizeof(path));
  totAll = 0;
  totCc = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a >> b >> c;
    path[a][b] = c;
    totAll += c;
  }
  int now = 1;
  isVisited[1] = 1;
  int cnt = 1;
  while (cnt != N + 1) {
    if (cnt > 2) isVisited[1] = 0;
    for (int i = 1; i <= N; i++) {
      if (not(isVisited[i]) and (path[now][i] != -1 or path[i][now] != -1)) {
        if (path[i][now] != -1) {
          totCc += path[i][now];
        }
        cnt++;
        now = i;
        isVisited[i] = 1;
        break;
      }
    }
  }
  cout << min(totCc, totAll - totCc) << endl;
}
