#include <bits/stdc++.h>
using namespace std;
struct tr {
  int f, t, c;
  void read() { scanf("%d%d%d", &f, &t, &c); }
};
const int MN = 120;
vector<pair<int, int> > G[MN];
bool W[MN];
int search(int x) {
  W[x] = true;
  for (int i = (0); i < (G[x].size()); ++i)
    if (!W[G[x][i].first]) return G[x][i].second + search(G[x][i].first);
  for (int i = (0); i < (G[x].size()); ++i)
    if (G[x][i].first == 1) return G[x][i].second;
}
int n;
int trav(bool dir) {
  for (int i = (0); i < (n + 1); ++i) W[i] = false;
  W[1] = true;
  int res = 0;
  if (dir) {
    res = search(G[1][0].first);
    res += G[1][0].second;
  } else {
    res = search(G[1][1].first);
    res += G[1][1].second;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    tr tmp;
    tmp.read();
    G[tmp.f].push_back(make_pair(tmp.t, 0));
    G[tmp.t].push_back(make_pair(tmp.f, tmp.c));
  }
  printf("%d\n", min(trav(true), trav(false)));
  return 0;
}
