#include <bits/stdc++.h>
using namespace std;
const int maxn = 228;
priority_queue<pair<long long, long long> > q2;
vector<pair<long long, long long> > g[maxn];
vector<long long> dis(maxn, 1e17);
void bfs(int v) {
  q2.push({0, v});
  while (!q2.empty()) {
    long long st = q2.top().second;
    long long cur = -q2.top().first;
    q2.pop();
    if (cur > dis[st]) {
      continue;
    }
    for (int i = 0; i < g[st].size(); i++) {
      long long to = g[st][i].first;
      long long len = g[st][i].second;
      if (cur + len < dis[to]) {
        dis[to] = cur + len;
        q2.push({-dis[to], to});
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    g[a[i]].push_back({b[i], 0});
    g[b[i]].push_back({a[i], c[i]});
  }
  int v = -1;
  int sec_v = -1;
  int help1 = -1;
  int help2 = -1;
  int fir_v = -1;
  for (int i = 0; i < n; i++) {
    if (g[a[i]].size() == 2 && g[a[i]][0].second == 0 &&
        g[a[i]][1].second == 0) {
      v = a[i];
      sec_v = g[a[i]][1].first;
      for (int j = 0; j < g[sec_v].size(); j++) {
        if (g[sec_v][j].first == v) {
          help1 = g[sec_v][j].second;
          break;
        }
      }
      fir_v = g[a[i]][0].first;
      for (int j = 0; j < g[fir_v].size(); j++) {
        if (g[fir_v][j].first == v) {
          help2 = g[fir_v][j].second;
          break;
        }
      }
      g[a[i]].pop_back();
      break;
    }
  }
  if (v == -1) {
    cout << 0;
    return 0;
  }
  dis[v] = 0;
  bfs(v);
  int ans1 = dis[0];
  for (int i = 0; i < n; i++) {
    if (ans1 < dis[i]) {
      ans1 = dis[i];
    }
  }
  for (int i = 0; i < n; i++) {
    dis[i] = 1e17;
  }
  g[v].pop_back();
  g[v].push_back({sec_v, 0});
  dis[v] = 0;
  bfs(v);
  int ans2 = dis[0];
  for (int i = 0; i < n; i++) {
    if (ans2 < dis[i]) {
      ans2 = dis[i];
    }
  }
  cout << min((ans1 + help1), (ans2 + help2));
  return 0;
}
