#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, pos;
int deg[N];
bool in[N];
long long a[2][N], d[N];
long long f[2][N], g[2][N];
vector<pair<int, int> > G[N];
vector<int> cir;
void dfs(int t, int u, int p, int id, long long w) {
  if (a[t][id] < w) {
    a[t][id] = w, pos = u;
  }
  for (auto v : G[u]) {
    if (v.first == p) continue;
    if (v.first != cir[id - 1] && in[v.first]) continue;
    dfs(t, v.first, u, id, w + v.second);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int u, v, l;
    cin >> u >> v >> l;
    G[u].push_back(pair<int, int>(v, l)), G[v].push_back(pair<int, int>(u, l));
    deg[u]++, deg[v]++;
  }
  queue<int> qu;
  for (int i = 1; i <= n; ++i) {
    if (deg[i] == 1) qu.push(i);
  }
  while (qu.size()) {
    int u = qu.front();
    qu.pop();
    for (auto v : G[u]) {
      if (deg[v.first] == 1) continue;
      deg[v.first]--;
      if (deg[v.first] == 1) qu.push(v.first);
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (deg[i] == 1) continue;
    int u = i;
    while (1) {
      in[u] = 1, cir.push_back(u);
      bool flag = 0;
      for (auto v : G[u]) {
        if (!in[v.first] && deg[v.first] != 1) {
          u = v.first, flag = 1;
          break;
        }
      }
      if (!flag) break;
    }
    break;
  }
  int sz = cir.size();
  for (int i = 1; i <= sz; ++i) {
    int u = cir[i - 1];
    pos = u;
    dfs(0, u, u, i, 0);
    dfs(1, pos, pos, i, 0);
    for (auto v : G[u]) {
      if (v.first == cir[i % sz]) d[i] = v.second;
    }
    d[i] += d[i - 1];
  }
  long long mx;
  mx = 0;
  for (int i = 1; i <= sz; ++i) {
    f[0][i] = max(f[0][i - 1], a[0][i] + d[i - 1]);
    f[1][i] = max(f[1][i - 1], a[0][i] + d[i - 1] + mx);
    f[1][i] = max(f[1][i], a[1][i]);
    mx = max(mx, a[0][i] - d[i - 1]);
  }
  mx = 0;
  for (int i = sz; i >= 1; --i) {
    g[0][i] = max(g[0][i + 1], a[0][i] + d[sz] - d[i - 1]);
    g[1][i] = max(g[1][i + 1], a[0][i] + d[sz] - d[i - 1] + mx);
    g[1][i] = max(g[1][i], a[1][i]);
    mx = max(mx, a[0][i] - (d[sz] - d[i - 1]));
  }
  long long res = f[1][sz];
  for (int i = 1; i < sz; ++i) {
    res = min(res, max(f[0][i] + g[0][i + 1], max(f[1][i], g[1][i + 1])));
  }
  cout << res;
}
