#include <bits/stdc++.h>
using namespace std;
const int MAX = 100 + 10;
int g[MAX][MAX];
int vis[MAX][MAX];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    memset(g, 0, sizeof(g));
    memset(vis, 0, sizeof(vis));
    int total = 0;
    for (int i = 0; i < n; i++) {
      int s, t, v;
      scanf("%d%d%d", &s, &t, &v);
      g[s][t] = v;
      total += v;
    }
    int ans = 0;
    int cur = 1;
    int flag = 1;
    while (flag) {
      flag = 0;
      for (int i = 1; i <= n; i++) {
        if (g[cur][i] && !vis[cur][i]) {
          flag = 1;
          vis[cur][i] = 1;
          cur = i;
          break;
        }
      }
      if (!flag) {
        for (int i = 1; i <= n; i++) {
          if (g[i][cur] && !vis[i][cur]) {
            flag = 1;
            vis[i][cur] = 1;
            ans += g[i][cur];
            cur = i;
            break;
          }
        }
      }
    }
    ans = min(ans, total - ans);
    printf("%d\n", ans);
  }
  return 0;
}
