#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct edge {
  int nx, t, w;
} e[200000 * 2 + 5];
int h[200000 + 5], en, a[200000 + 5], an, z[200000 + 5], u[200000 + 5];
long long Ans, d[200000 + 5], s[200000 + 5], f1[200000 + 5], f2[200000 + 5],
    lf[200000 + 5], rf[200000 + 5];
inline void ins(int x, int y, int w) {
  e[++en] = (edge){h[x], y, w};
  h[x] = en;
  e[++en] = (edge){h[y], x, w};
  h[y] = en;
}
void dfs(int x, int fa) {
  z[++u[x]] = x;
  for (int i = h[x]; i; i = e[i].nx)
    if (e[i].t != fa)
      if (!u[e[i].t])
        u[e[i].t] = u[x], dfs(e[i].t, x);
      else if (!an)
        for (int j = u[e[i].t]; j <= u[x]; ++j) a[++an] = z[j];
}
void dp(int x) {
  u[x] = 0;
  for (int i = h[x]; i; i = e[i].nx)
    if (u[e[i].t]) {
      dp(e[i].t);
      Ans = max(Ans, d[x] + d[e[i].t] + e[i].w);
      d[x] = max(d[x], d[e[i].t] + e[i].w);
    }
}
int main() {
  int n = read(), i, j, y;
  long long x, ans = (1LL << 60);
  for (i = 1; i <= n; ++i) x = read(), y = read(), ins(x, y, read());
  dfs(1, 0);
  for (i = 1; i <= an; ++i) u[a[i]] = 0;
  for (i = 1; i <= an; ++i) dp(a[i]);
  for (a[0] = a[an], i = 1; i <= an; ++i)
    for (j = h[a[i]]; j; j = e[j].nx)
      if (e[j].t == a[i - 1]) s[i] = s[i - 1] + e[j].w;
  memset(f1, 200, sizeof(f1));
  memset(f2, 200, sizeof(f2));
  memset(lf, 200, sizeof(lf));
  memset(rf, 200, sizeof(rf));
  for (x = -(1LL << 60), i = 1; i <= an; ++i) {
    f1[i] = max(f1[i - 1], d[a[i]] + s[an] + s[i]);
    lf[i] = max(lf[i - 1], d[a[i]] + s[i] + x);
    x = max(x, d[a[i]] - s[i]);
  }
  for (x = -(1LL << 60), i = an; i; --i) {
    f2[i] = max(f2[i + 1], d[a[i]] - s[i]);
    rf[i] = max(rf[i + 1], d[a[i]] - s[i] + x);
    x = max(x, d[a[i]] + s[i]);
  }
  for (i = 1; i <= an; ++i)
    ans = min(ans, max(max(lf[i - 1], rf[i]), f1[i - 1] + f2[i]));
  printf("%I64d", max(ans, Ans));
}
