#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 200011;
struct Edge {
  long long v, w, nxt;
} e[MAXN << 1];
long long n, tmp, ans = -1;
long long mn[MAXN];
long long head[MAXN], cnt = 1;
long long pp[MAXN], ss[MAXN];
long long pre[MAXN], suf[MAXN];
long long a[MAXN], dis[MAXN], tot;
bool vis[MAXN], on_circle[MAXN];
long long read() {
  long long X = 0, F = 1;
  char C = getchar();
  while (C < '0' || C > '9') {
    if (C == '-') F = -1;
    C = getchar();
  }
  while (C >= '0' && C <= '9') {
    X = X * 10 + C - '0';
    C = getchar();
  }
  return X * F;
}
void add_Edge(long long u, long long v, long long w) {
  e[++cnt] = (Edge){v, w, head[u]};
  head[u] = cnt;
  e[++cnt] = (Edge){u, w, head[v]};
  head[v] = cnt;
}
bool dfs(long long u, long long fa, long long id) {
  vis[u] = 1;
  bool flag = 0;
  for (long long i = head[u]; i; i = e[i].nxt) {
    if (i == (id ^ 1)) continue;
    if (vis[e[i].v]) {
      tmp = e[i].v;
      flag = 1;
      a[++tot] = u;
      on_circle[u] = 1;
      dis[tot] = e[i].w;
      return 1;
    }
    flag |= dfs(e[i].v, u, i);
    if (flag) {
      a[++tot] = u;
      on_circle[u] = 1;
      dis[tot] = e[i].w;
    }
    if (flag || tmp) break;
  }
  if (tmp == u)
    return 0;
  else
    return flag;
}
void dfs(long long u, long long fa) {
  long long maxn1 = 0, maxn2 = 0;
  for (long long i = head[u]; i; i = e[i].nxt) {
    if (e[i].v == fa) continue;
    dfs(e[i].v, u);
    mn[u] = max(mn[u], mn[e[i].v] + e[i].w);
    if (mn[e[i].v] + e[i].w >= maxn1) {
      maxn2 = maxn1;
      maxn1 = mn[e[i].v] + e[i].w;
    } else if (mn[e[i].v] + e[i].w > maxn2)
      maxn2 = mn[e[i].v] + e[i].w;
  }
  ans = max(ans, maxn1 + maxn2);
}
void update(int &maxn1, int &id1, int &maxn2, int &id2, long long x,
            long long id) {
  if (x > maxn1)
    maxn2 = maxn1, id2 = id1, maxn1 = x, id1 = id;
  else if (x > maxn2)
    maxn2 = x, id2 = id;
}
void calc() {
  for (long long i = 1; i <= tot; ++i) {
    long long maxn1 = 0, maxn2 = 0;
    for (long long j = head[a[i]]; j; j = e[j].nxt)
      if (!on_circle[e[j].v]) {
        dfs(e[j].v, a[i]);
        mn[a[i]] = max(mn[a[i]], mn[e[j].v] + e[j].w);
        if (mn[e[j].v] + e[j].w >= maxn1) {
          maxn2 = maxn1;
          maxn1 = mn[e[j].v] + e[j].w;
        } else if (mn[e[j].v] + e[j].w > maxn2)
          maxn2 = mn[e[j].v] + e[j].w;
      }
    ans = max(ans, maxn1 + maxn2);
  }
  long long ans2 = 1ll * 114514191 * 11451419191;
  dis[tot + 1] = dis[1];
  dis[1] = 0;
  for (long long i = 1; i <= tot; ++i) dis[i] += dis[i - 1];
  long long mx = 0;
  for (long long i = 1; i <= tot; ++i) {
    pre[i] = max(pre[i - 1], mx + dis[i] + mn[a[i]]);
    mx = max(mx, -dis[i] + mn[a[i]]);
    pp[i] = max(pp[i - 1], dis[i] + mn[a[i]]);
  }
  mx = 0;
  for (long long i = tot; i; --i) {
    suf[i] = max(suf[i + 1], mx - dis[i] + mn[a[i]]);
    mx = max(mx, dis[i] + mn[a[i]]);
    ss[i] = max(ss[i + 1], dis[tot] - dis[i] + mn[a[i]]);
  }
  for (long long i = 2; i <= tot; ++i) {
    ans2 = min(ans2,
               max(pp[i - 1] + ss[i] + dis[tot + 1], max(pre[i - 1], suf[i])));
  }
  ans2 = max(ans, min(ans2, pre[tot]));
  printf("%lld\n", ans2);
}
int main() {
  n = read();
  for (long long i = 1, u, v, w; i <= n; ++i) {
    u = read();
    v = read();
    w = read();
    add_Edge(u, v, w);
  }
  dfs(1, 0, 0);
  calc();
  return 0;
}
