#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int> > cost;
  vector<int> used;
  int n, from, to, tmpcost;
  int sum1 = 0, sum = 0;
  cin >> n;
  cost.resize(n, vector<int>(n));
  used.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> from >> to >> tmpcost;
    sum += tmpcost;
    cost[from - 1][to - 1] = tmpcost;
    cost[to - 1][from - 1] = -tmpcost;
  }
  used[0] = 1;
  int cur = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < n; j++) {
      if (used[j]) continue;
      if (cost[cur][j] > 0) {
        used[j] = 1;
        cur = j;
        break;
      } else if (cost[cur][j] < 0) {
        used[j] = 1;
        sum1 -= cost[cur][j];
        cur = j;
        break;
      }
    }
  }
  if (cost[cur][0] < 0) sum1 -= cost[cur][0];
  if (sum1 < sum - sum1) {
    cout << sum1 << endl;
  } else {
    cout << sum - sum1 << endl;
  }
  return 0;
}
