#include <bits/stdc++.h>
using namespace std;
int n, ans = 1e9, x, y, z;
vector<vector<pair<int, int> > > in;
vector<vector<pair<int, int> > > out;
void dfs(int start, int node, int &cost, int bef) {
  if (node == start) return;
  if (out[node].size() == 1) {
    if (out[node][0].first == bef) {
      cost += in[node][0].second;
      dfs(start, in[node][0].first, cost, node);
    } else {
      dfs(start, out[node][0].first, cost, node);
    }
  } else if (out[node].size() == 2) {
    if (out[node][0].first == bef) {
      dfs(start, out[node][1].first, cost, node);
    } else {
      dfs(start, out[node][0].first, cost, node);
    }
  } else if (out[node].size() == 0) {
    if (in[node][0].first == bef) {
      cost += in[node][1].second;
      dfs(start, in[node][1].first, cost, node);
    } else {
      cost += in[node][0].second;
      dfs(start, in[node][0].first, cost, node);
    }
  }
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  in = vector<vector<pair<int, int> > >(n + 1);
  out = vector<vector<pair<int, int> > >(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> z;
    in[y].push_back({x, z});
    out[x].push_back({y, z});
  }
  for (int i = 1; i <= n; i++) {
    if (out[i].size() > 1) {
      int temp = 0;
      dfs(i, out[i][0].first, temp, i);
      ans = temp;
      temp = 0;
      dfs(i, out[i][1].first, temp, i);
      min(ans, temp);
      ans = min(ans, temp);
      break;
    }
  }
  (ans == 1e9) ? cout << 0 : cout << ans;
  return 0;
}
