#include <bits/stdc++.h>
using namespace std;
int known[200];
vector<pair<int, int> > v[101];
int minn = 1000000000;
int ans = 0;
stack<int> st;
int curr;
void dfs(int i) {
  known[i] = 1;
  st.push(i);
  int k;
  int fl = 0;
  for (k = 0; k < v[i].size(); k++) {
    if (known[v[i][k].first] == 0) {
      fl = 1;
      ans += v[i][k].second;
      dfs(v[i][k].first);
    }
  }
  if (fl == 0) {
    for (k = 0; k < v[i].size(); k++) {
      if (v[i][k].first == curr) {
        ans += v[i][k].second;
      }
    }
    if (ans < minn) {
      minn = ans;
    }
    ans = 0;
  }
  known[st.top()] = 0;
  st.pop();
  return;
}
int main() {
  int n;
  cin >> n;
  int i;
  int x, y, z;
  for (i = 0; i < n; i++) {
    cin >> x >> y >> z;
    pair<int, int> a;
    a.first = y;
    a.second = 0;
    v[x].push_back(a);
    a.first = x;
    a.second = z;
    v[y].push_back(a);
  }
  for (i = 1; i <= n; i++) {
    curr = i;
    ans = 0;
    dfs(i);
  }
  printf("%d\n", minn);
  return 0;
}
