#include <bits/stdc++.h>
using namespace std;
long double pi = 3.141592653589793238;
set<long long>::iterator it;
multiset<long long>::iterator itr;
vector<bool> v;
vector<vector<long long>> g;
void edge(long long a, long long b) {
  g[a].push_back(b);
  g[b].push_back(a);
}
void bfs(long long u) {
  queue<long long> q;
  q.push(u);
  v[u] = true;
  while (!q.empty()) {
    long long first = q.front();
    q.pop();
    cout << first + 1 << " ";
    for (auto i = g[first].begin(); i != g[first].end(); i++) {
      if (!v[*i]) {
        q.push(*i);
        v[*i] = true;
      }
    }
  }
}
vector<long long> ans;
void DFSUtil(long long u, vector<vector<long long>> g, vector<bool> &visited) {
  visited[u] = true;
  ans.push_back(u + 1);
  for (long long i = 0; i < (long long)g[u].size(); i++)
    if (visited[g[u][i]] == false) DFSUtil(g[u][i], g, visited);
}
void DFS(vector<vector<long long>> g, long long V) {
  vector<bool> visited(V, false);
  for (long long u = 0; u < V; u++)
    if (visited[u] == false) DFSUtil(u, g, visited);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  t = 1;
  while (t--) {
    long long n;
    cin >> n;
    g.assign(n, vector<long long>());
    set<tuple<long long, long long, long long>> v1;
    for (long long i = 0; i < n; i++) {
      long long x, y, c;
      cin >> x >> y >> c;
      x--;
      y--;
      v1.insert(make_tuple(x + 1, y + 1, c));
      edge(x, y);
    }
    DFS(g, n);
    long long sum1 = 0;
    long long sum2 = 0;
    for (long long i = 0; i < (long long)ans.size(); i++) {
      long long f2 = ans[i];
      long long f1;
      if (i != 0)
        f1 = ans[i - 1];
      else
        f1 = ans[ans.size() - 1];
      auto it = v1.lower_bound(make_tuple(f1, f2, 0));
      auto itr = v1.lower_bound(make_tuple(f2, f1, 0));
      if (it == v1.end() || get<0>(*it) != f1 || get<1>(*it) != f2) {
        sum1 = sum1 + get<2>(*itr);
      } else {
        sum2 = sum2 + get<2>(*it);
      }
    }
    cout << min(sum1, sum2) << endl;
  }
}
