#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
long long nnu[25];
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (!x) {
    putchar('0');
    return;
  }
  long long tp = 0;
  while (x) nnu[++tp] = x % 10, x /= 10;
  while (tp) putchar(nnu[tp--] + '0');
  return;
}
long long head[1000005], to[1000005 << 1], nxt[1000005 << 1], v[1000005 << 1],
    cnt = 1;
inline void link(long long x, long long y, long long w) {
  to[++cnt] = y;
  nxt[cnt] = head[x];
  head[x] = cnt;
  v[cnt] = w;
  to[++cnt] = x;
  nxt[cnt] = head[y];
  head[y] = cnt;
  v[cnt] = w;
  return;
}
long long cir[1000005], len;
long long st[1000005], tp;
bool vis[1000005], tag[1000005];
void dfs1(long long x, long long f) {
  if (len) return;
  if (vis[x]) {
    long long but = tp;
    while (st[but] ^ x) but--;
    for (long long i = but; i <= tp; i++) cir[++len] = st[i], tag[cir[len]] = 1;
    return;
  }
  vis[x] = 1;
  st[++tp] = x;
  for (long long i = head[x]; i; i = nxt[i]) {
    if ((i ^ 1) == f) continue;
    long long t = to[i];
    dfs1(t, i);
  }
  tp--;
  return;
}
long long D;
long long dep[1000005];
void dfs2(long long x, long long f) {
  long long mx = 0, mx2 = 0;
  for (long long i = head[x]; i; i = nxt[i]) {
    long long t = to[i];
    if (t == f || tag[t]) continue;
    dfs2(t, x);
    if (dep[t] + v[i] > mx)
      mx2 = mx, mx = dep[t] + v[i];
    else if (dep[t] + v[i] > mx2)
      mx2 = dep[t] + v[i];
  }
  D = max(D, mx + mx2);
  dep[x] = mx;
  return;
}
long long totdis;
long long dis[1000005];
bool vis2[1000005];
void dfs3(long long x, long long id, long long f) {
  if (vis2[x]) return;
  vis2[x] = 1;
  dis[x] = totdis;
  for (long long i = head[x]; i; i = nxt[i]) {
    long long t = to[i];
    if (t == f) continue;
    if (t != cir[1] && t != cir[id + 1]) continue;
    totdis += v[i];
    dfs3(t, id + 1, x);
  }
  return;
}
struct nod1 {
  long long data, val;
  nod1() {}
  nod1(long long d, long long va) { data = d, val = va; }
};
inline bool operator<(nod1 x, nod1 y) { return x.val < y.val; }
inline bool operator>(nod1 x, nod1 y) { return x.val > y.val; }
priority_queue<nod1> q1;
priority_queue<nod1> q2;
inline long long ck(long long x, long long y) {
  return dep[x] + dep[y] + abs(dis[x] - dis[y]);
}
signed main() {
  long long n = read();
  for (long long i = 1; i <= n; i++) {
    long long x = read(), y = read(), z = read();
    link(x, y, z);
  }
  dfs1(1, 0);
  for (long long i = 1; i <= len; i++) dfs2(cir[i], cir[i]);
  dfs3(cir[1], 1, 0);
  for (long long i = 1; i <= len; i++)
    q1.push((nod1){cir[i], dep[cir[i]] - dis[cir[i]]});
  for (long long i = 1; i <= len; i++)
    q2.push((nod1){cir[i], dep[cir[i]] + dis[cir[i]]});
  long long ans = (1ll << 60);
  for (long long i = 1; i <= len; i++) {
    nod1 x = q1.top(), y = q2.top();
    while (dep[x.data] - dis[x.data] != x.val) q1.pop(), x = q1.top();
    while (dep[y.data] + dis[y.data] != y.val) q2.pop(), y = q2.top();
    if (x.data == y.data) {
      q1.pop(), q2.pop();
      nod1 xx = q1.top(), yy = q2.top();
      while (dep[xx.data] - dis[xx.data] != xx.val) q1.pop(), xx = q1.top();
      while (dep[yy.data] + dis[yy.data] != yy.val) q2.pop(), yy = q2.top();
      ans = min(ans, max(ck(x.data, yy.data), ck(y.data, xx.data)));
      q1.push(x), q2.push(y);
    } else
      ans = min(ans, ck(x.data, y.data));
    dis[cir[i]] = dis[cir[i == 1 ? len : i - 1]] + totdis -
                  (dis[cir[i == 1 ? len : i - 1]] - dis[cir[i]]);
    q1.push((nod1){cir[i], dep[cir[i]] - dis[cir[i]]});
    q2.push((nod1){cir[i], dep[cir[i]] + dis[cir[i]]});
  }
  printf("%0.0lf\n", max(D, ans) / 1.0);
}
