#include <bits/stdc++.h>
using namespace std;
bool *flag;
int sum_p = 0, sum_n = 0, N;
struct Node {
  int a, b, c;
  string dir;
};
vector<Node> node;
vector<Node> res_node;
bool equal(Node n1, Node n2) {
  if (n1.a == n2.a && n1.b == n2.b && n1.c == n2.c) {
    return true;
  } else
    return false;
}
void sort() {
  res_node.push_back(node[0]);
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (res_node[i - 1].b == node[j].a) {
        res_node.push_back(node[j]);
        break;
      } else if (res_node[i - 1].b == node[j].b &&
                 !equal(res_node[i - 1], node[j])) {
        int temp = node[j].a;
        node[j].a = node[j].b;
        node[j].b = temp;
        node[j].dir = "l";
        res_node.push_back(node[j]);
        break;
      }
    }
  }
}
int main() {
  cin >> N;
  int n = N;
  flag = new bool[n];
  for (int i = 0; i < n; i++) flag[i] = false;
  while (n) {
    int a, b, c;
    Node n1;
    cin >> a >> b >> c;
    n1.a = a;
    n1.b = b;
    n1.c = c;
    n1.dir = "r";
    node.push_back(n1);
    n--;
  }
  sort();
  for (int i = 0; i < N; i++) {
    if (res_node[i].dir == "r") {
      sum_n += res_node[i].c;
    } else {
      sum_p += res_node[i].c;
    }
  }
  if (sum_p > sum_n) {
    cout << sum_n << endl;
  } else
    cout << sum_p << endl;
  return 0;
}
