#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, ll>;
const int maxn = 2.1e5;
int n, m, vis[maxn], in[maxn], sta[maxn], top, a[maxn], val[maxn];
ll fir[maxn], sec[maxn], mx[maxn], s0[maxn], s1[maxn], t0[maxn], t1[maxn];
vector<PII> e[maxn];
bool findcir(int u, int fa) {
  if (vis[u]) {
    while (1) {
      int now = sta[top];
      in[now] = 1;
      a[++m] = now;
      --top;
      if (now == u) return 1;
    }
  }
  vis[u] = 1;
  sta[++top] = u;
  int tmp = top;
  for (auto E : e[u]) {
    if (E.first == fa) continue;
    if (findcir(E.first, u)) return 1;
    top = tmp;
  }
  return 0;
}
void geteval(int u, int to) {
  if (to == m + 1) return;
  for (auto E : e[u]) {
    if (E.first != a[to + 1]) continue;
    val[to] = E.second;
    geteval(E.first, to + 1);
  }
}
ll getmx(int u, int fa) {
  ll res = 0;
  for (auto E : e[u]) {
    if (E.first == fa || in[E.first]) continue;
    ll tmp = getmx(E.first, u), now = fir[E.first] + E.second;
    res = max(res, tmp);
    if (now > fir[u])
      sec[u] = fir[u], fir[u] = now;
    else if (now > sec[u])
      sec[u] = now;
  }
  res = max(res, fir[u] + sec[u]);
  return res;
}
signed main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x, y, w;
    cin >> x >> y >> w;
    e[x].push_back({y, w});
    e[y].push_back({x, w});
  }
  findcir(1, 0);
  a[m + 1] = a[1];
  geteval(a[1], 1);
  for (int i = 1; i <= m; ++i) mx[i] = getmx(a[i], 0);
  ll tmp = 0;
  for (int i = 1; i < m; ++i) {
    s0[i] = max(s0[i - 1], tmp + fir[a[i]]);
    tmp += val[i];
  }
  tmp = 0;
  for (int i = m; i > 1; --i) {
    s1[i] = max(s1[i + 1], tmp + fir[a[i]]);
    tmp += val[i - 1];
  }
  tmp = 0;
  for (int i = 1; i <= m; ++i) {
    t0[i] = max(t0[i - 1], max(mx[i], tmp + fir[a[i]]));
    tmp = max(tmp, fir[a[i]]);
    tmp += val[i];
  }
  tmp = 0;
  for (int i = m; i > 1; --i) {
    t1[i] = max(t1[i + 1], max(mx[i], tmp + fir[a[i]]));
    tmp = max(tmp, fir[a[i]]);
    tmp += val[i - 1];
  }
  ll ans = t0[m];
  for (int i = 1; i < m; ++i) {
    ans = min(ans, max(max(t0[i], t1[i + 1]), s0[i] + s1[i + 1] + val[m]));
  }
  cout << ans << endl;
  return 0;
}
