#include <bits/stdc++.h>
using namespace std;
int n;
int he[400050], ne[400050 << 2], to[400050 << 2], w[400050 << 2], tot = 1;
inline void addedge(int x, int y, int z) {
  to[++tot] = y;
  ne[tot] = he[x];
  he[x] = tot;
  w[tot] = z;
  to[++tot] = x;
  ne[tot] = he[y];
  he[y] = tot;
  w[tot] = z;
}
long long dep[400050], md[400050], an1 = 0, an2 = 1e18;
int lim, a[400050], b[400050], pd[400050];
inline void dfs(int g, int f) {
  dep[g] = dep[to[f ^ 1]] + 1;
  for (int i = he[g]; i; i = ne[i]) {
    if (i == (f ^ 1)) continue;
    if (dep[to[i]]) {
      a[++a[0]] = g;
      b[dep[g] - dep[to[i]] + 1] = i;
      lim = dep[to[i]];
      return;
      return;
    }
    dfs(to[i], i);
    if (lim) {
      if (dep[g] >= lim) a[++a[0]] = g, b[a[0] - 1] = i ^ 1;
      return;
    }
  }
}
inline void dfs1(int g, int fa) {
  md[g] = 0;
  long long d2 = 0;
  for (int i = he[g]; i; i = ne[i]) {
    if (to[i] == fa || pd[to[i]]) continue;
    dfs1(to[i], g);
    d2 = md[to[i]] + w[i];
    an1 = max(an1, d2 + md[g]);
    if (d2 > md[g]) md[g] = d2;
  }
}
int dq[400050], fr, ba;
long long val[400050], ans[400050], sum[400050];
multiset<pair<long long, int> > s, s2;
long long ma[400050 << 2];
inline void build(int g, int l, int r) {
  if (l == r) {
    ma[g] = val[l];
    return;
  }
  const int m = l + r >> 1;
  build(g << 1, l, m);
  build(g << 1 | 1, m + 1, r);
  ma[g] = max(ma[g << 1], ma[g << 1 | 1]);
}
inline long long ask(int g, int l, int r, int x, int y) {
  if (l > y || r < x) return 0;
  if (l >= x && r <= y) return ma[g];
  const int m = l + r >> 1;
  return max(ask(g << 1, l, m, x, y), ask(g << 1 | 1, m + 1, r, x, y));
}
inline void work() {
  dfs(1, 0);
  for (int i = 1; i <= a[0]; ++i) {
    a[i + a[0]] = a[i], b[i + a[0]] = b[i];
    pd[a[i]] = 1;
  }
  for (int i = 1; i <= a[0]; ++i) dfs1(a[i], 0);
  int m = a[0] + a[0];
  for (int i = 1; i <= m; ++i) sum[i] = sum[i - 1] + w[b[i - 1]];
  for (int i = 1; i <= a[0]; ++i) {
    s.insert(make_pair(md[a[i]] - sum[i], i));
    s2.insert(make_pair(md[a[i]] + sum[i], i));
  }
  multiset<pair<long long, int> >::iterator it1, it2;
  for (int i = a[0] + 1; i <= m; ++i) {
    s.erase(s.find(make_pair(md[a[i - a[0]]] - sum[i - a[0]], i - a[0])));
    s2.erase(s2.find(make_pair(md[a[i - a[0]]] + sum[i - a[0]], i - a[0])));
    s.insert(make_pair(md[a[i]] - sum[i], i));
    s2.insert(make_pair(md[a[i]] + sum[i], i));
    it1 = s.end();
    it2 = s2.end();
    --it1, --it2;
    long long val;
    if ((*it1).second == (*it2).second) {
      --it2;
      val = (*it1).first + (*it2).first;
      --it1;
      ++it2;
      val = max(val, (*it1).first + (*it2).first);
    } else {
      val = (*it1).first + (*it2).first;
    }
    an2 = min(an2, val);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y, z; i <= n; ++i)
    scanf("%d%d%d", &x, &y, &z), addedge(x, y, z);
  work();
  printf("%lld\n", max(an1, an2));
  return 0;
}
