#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> edge[400005], len[400005];
void add(long long u, long long v, long long w) {
  edge[u].push_back(v);
  len[u].push_back(w);
}
long long path[400005], vis[400005], fa[400005], to_fa[400005], cnt, tot,
    dis[400005], on[400005];
void dfs(long long u) {
  vis[u] = ++tot;
  for (long long i = 0; i < edge[u].size(); i++) {
    long long v = edge[u][i];
    if (v == fa[u]) continue;
    if (vis[v]) {
      if (vis[v] < vis[u]) {
        long long now = u;
        for (; now != v; now = fa[now]) {
          on[now] = 1;
          path[++cnt] = now;
          dis[cnt] = to_fa[now];
        }
        path[++cnt] = v;
        dis[cnt] = len[u][i];
        on[v] = 1;
      }
      continue;
    } else
      fa[v] = u, to_fa[v] = len[u][i], dfs(v);
  }
}
long long fir[400005], sec[400005], d[400005], qaq[400005], a[400005];
void dfs2(long long u, long long fa, long long id) {
  fir[u] = sec[u] = qaq[u];
  for (long long i = 0; i < edge[u].size(); i++) {
    long long v = edge[u][i];
    if (on[v] || v == fa) continue;
    qaq[v] = qaq[u] + len[u][i];
    dfs2(v, u, id);
    if (fir[v] > fir[u])
      swap(fir[u], sec[u]), fir[u] = fir[v];
    else
      sec[u] = max(sec[u], fir[v]);
  }
  d[id] = max(d[id], fir[u] + sec[u] - 2 * qaq[u]);
}
long long ans = 1ll << 50;
long long t1[400005], t2[400005], cha, ty[400005];
set<pair<long long, long long> > r1, r2;
set<pair<long long, long long> >::iterator it1, it2;
signed main() {
  long long a1;
  cin >> n;
  for (long long i = 1, u, v, w; i <= n; i++) {
    cin >> u >> v >> w;
    if (i == 1) a1 = u;
    add(u, v, w);
    add(v, u, w);
  }
  dfs(1);
  long long luzy = 0;
  for (long long i = 1; i <= cnt; i++) {
    dfs2(path[i], 0, i);
    a[i] = fir[path[i]];
    luzy = max(luzy, d[i]);
  }
  for (long long i = cnt; i >= 1; i--) {
    ty[i] += ty[i + 1] + dis[i];
    if (i == 1) ty[i] = 0;
    t1[i] = ty[i] + a[i];
    t2[i] = a[i] - ty[i];
    r1.insert(make_pair(t1[i], i));
    r2.insert(make_pair(t2[i], i));
  }
  for (long long i = 1; i <= cnt; i++) {
    long long p = luzy;
    it1 = r1.end();
    it2 = r2.end();
    it1--;
    it2--;
    if ((*it1).second != (*it2).second)
      p = max(p, (*it1).first + (*it2).first);
    else {
      it1--;
      p = max(p, (*it1).first + (*it2).first);
      it1++;
      it2--;
      p = max(p, (*it1).first + (*it2).first);
      it2++;
    }
    ans = min(ans, p);
    cha += dis[i];
    if (i != cnt) {
      it1 = r1.find(make_pair(t1[i + 1], i + 1));
      it2 = r2.find(make_pair(t2[i + 1], i + 1));
      r1.erase(it1);
      r2.erase(it2);
      t1[i + 1] = a[i + 1] - cha;
      t2[i + 1] = a[i + 1] + cha;
      r1.insert(make_pair(t1[i + 1], i + 1));
      r2.insert(make_pair(t2[i + 1], i + 1));
    }
  }
  cout << ans << endl;
}
