#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-6;
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) {
  return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y)));
}
double SQSUM(double x, double y) { return x * x + y * y; }
template <class T>
bool INRANGE(T x, T a, T b) {
  return a <= x && x <= b;
}
int main() {
  int N;
  scanf("%d ", &N);
  vector<int> a;
  vector<int> b;
  vector<int> c;
  for (int i = 0; i < N; i++) {
    {
      int n, m, o;
      scanf("%d %d %d ", &n, &m, &o);
      a.push_back(n);
      b.push_back(m);
      c.push_back(o);
    }
  }
  int now = 0;
  int city = b[now];
  vector<bool> visited(N);
  int sum[2] = {0, 0};
  int sec;
  int i;
  do {
    for (i = 0; i < N; i++) {
      if (!visited[i]) {
        if (city == a[i]) {
          sec = 0;
          sum[sec] += c[i];
          city = b[i];
          now = i;
          visited[i] = true;
          break;
        } else if (city == b[i]) {
          sec = 1;
          sum[sec] += c[i];
          city = a[i];
          now = i;
          visited[i] = true;
          break;
        }
      }
    }
  } while (i != N);
  printf("%d\n", min(sum[0], sum[1]));
  return 0;
}
