#include <bits/stdc++.h>
using namespace std;
void hora() {
  time_t t;
  time(&t);
  struct tm* petm = localtime(&t);
  FILE* pfile;
  pfile = fopen("compilaciones.txt", "a");
  fprintf(pfile, " \n");
  fprintf(pfile, "compil�: %s\n", asctime(petm));
  fclose(pfile);
}
vector<int> E[100], W[100];
int color[100];
int dfs(int u, int pat) {
  color[u] = 1;
  int res = 0;
  for (int i = 0; i < E[u].size(); i++) {
    int v = E[u][i];
    int w = max(W[u][i], 0);
    if (v == pat) continue;
    if (color[v] && v != pat) return w;
    return dfs(v, u) + w;
  }
}
int n;
int a, b, w;
int main() {
  cin >> n;
  for (int t = 0; t < n; t++) {
    scanf("%d%d%d", &a, &b, &w);
    a--;
    b--;
    E[a].push_back(b);
    E[b].push_back(a);
    W[a].push_back(w);
    W[b].push_back(-w);
  }
  int res = (1 << 30);
  for (int i = 0; i < 2; i++) {
    memset(color, 0, sizeof(color));
    res = min(res, dfs(0, E[0][i]));
  }
  cout << res << endl;
}
