#include <bits/stdc++.h>
using namespace std;
int g[103][103];
int n;
bool visited[103];
int ans = 0;
bool was = true;
int cnt = 0;
void printAns(int cnt1) {
  int res = min(cnt1, cnt - cnt1);
  printf("%d", res);
}
int main() {
  scanf("%d", &n);
  int u, v, c;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &u, &v, &c);
    g[u][v] = c;
    cnt += c;
  }
  stack<int> q;
  q.push(1);
  visited[1] = true;
  while (!q.empty()) {
    v = q.top();
    q.pop();
    was = false;
    for (int i = 1; i <= n; i++) {
      if (!visited[i] && g[v][i]) {
        ans += g[v][i];
        g[v][i] = 0;
        if (i == 1) {
          printAns(ans);
          return 0;
        }
        visited[i] = true;
        q.push(i);
        was = true;
        break;
      }
    }
    if (!was) {
      for (int i = 1; i <= n; i++) {
        if (!visited[i] && g[i][v]) {
          if (i == 1) {
            printAns(ans);
            return 0;
          }
          visited[i] = true;
          g[v][i] = 0;
          q.push(i);
          was = true;
          break;
        }
      }
    }
    if (!was && g[v][1]) {
      ans += g[v][1];
    }
  }
  int res = min(ans, cnt - ans);
  printf("%d", res);
  return 0;
}
