#include <bits/stdc++.h>
using namespace std;
bool contains(vector<int> &path, int elem) {
  for (int i = 0; i < path.size(); i++) {
    if (path[i] == elem) return true;
  }
  return false;
}
int findNextPath(vector<vector<int>> &graph, vector<int> &path, int index) {
  int N = graph.size();
  for (int i = 0; i < N; i++) {
    if ((graph[index][i] != 0 && !contains(path, i)) ||
        (graph[i][index] != 0) && !contains(path, i))
      return i;
  }
  return -1;
}
int main() {
  int N, clockWise = 0, anticlockwise = 0;
  cin >> N;
  vector<vector<int>> graph(N, vector<int>(N, 0));
  for (int i = 0; i < N; i++) {
    int a, b, cost;
    cin >> a >> b >> cost;
    graph[a - 1][b - 1] = cost;
  }
  vector<int> path{0};
  while (true) {
    int index = path[path.size() - 1];
    int res = findNextPath(graph, path, index);
    if (res != -1)
      path.push_back(res);
    else
      break;
  }
  for (int i = 0; i < N - 1; i++) {
    clockWise += graph[path[i]][path[i + 1]];
  }
  clockWise += graph[path[N - 1]][path[0]];
  for (int i = N - 1; i > 0; i--) anticlockwise += graph[path[i]][path[i - 1]];
  anticlockwise += graph[path[0]][path[N - 1]];
  if (clockWise > anticlockwise)
    cout << anticlockwise;
  else
    cout << clockWise;
  return 0;
}
