#include <bits/stdc++.h>
using namespace std;
template <class t, class u>
void chmax(t &first, u second) {
  if (first < second) first = second;
}
template <class t, class u>
void chmin(t &first, u second) {
  if (second < first) first = second;
}
vector<pair<int, int> > G[102];
bool used[102];
int f(int fro, int par) {
  if (used[fro]) return 0;
  used[fro] = 1;
  int MIN;
  for (pair<int, int> &to : G[fro]) {
    if (to.first == par) continue;
    MIN = f(to.first, fro) + to.second;
  }
  return MIN;
}
int main() {
  int n;
  scanf("%d", &n);
  memset(used, 0, sizeof(used));
  for (int i = int(0); i < int(n); i++) {
    int first, second, c;
    scanf("%d", &first);
    scanf("%d", &second);
    scanf("%d", &c);
    --first;
    --second;
    G[first].emplace_back(make_pair(second, 0));
    G[second].emplace_back(make_pair(first, c));
  }
  int res = (int)1e9;
  for (pair<int, int> &to : G[0]) {
    memset(used, 0, sizeof(used));
    used[0] = 1;
    chmin(res, f(to.first, 0) + to.second);
  }
  printf("%d\n", res);
  return 0;
}
