#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int head[N], nxt[N * 2], v[N * 2], cnt = 1;
double w[N * 2], dia[N], z, dmx[N], Fn;
int n, m, x, y;
inline void read(int &v) {
  v = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') v = v * 10 + c - '0', c = getchar();
}
inline void read(double &v) {
  v = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') v = v * 10 + c - '0', c = getchar();
}
void add(int ux, int vx, double wx) {
  nxt[++cnt] = head[ux];
  head[ux] = cnt;
  v[cnt] = vx;
  w[cnt] = wx;
  nxt[++cnt] = head[vx];
  head[vx] = cnt;
  v[cnt] = ux;
  w[cnt] = wx;
}
int tot = 0, top = 0, st[N], cr[N * 2], vis[N], suc = 0, fc[N];
double crD[N * 2], stD[N];
void dfsCir(int x, int fa) {
  vis[x] = 1;
  if (x == 1) st[++top] = x, stD[top] = 0;
  for (register int i = head[x]; i; i = nxt[i]) {
    int vv = v[i];
    if (vv == fa) continue;
    if (!vis[vv]) {
      st[++top] = vv;
      stD[top] = w[i];
      dfsCir(vv, x);
    } else {
      suc = 1;
      while (st[top] != vv) {
        fc[st[top]] = 1;
        cr[++tot] = st[top];
        crD[tot] = stD[top--];
      }
      fc[st[top]] = 1;
      cr[++tot] = st[top];
      crD[tot] = w[i];
      return;
    }
    if (suc) return;
  }
  top--;
}
int pos;
double mxD;
void dfsTrD(int x, double dix, int fa) {
  if (dix > mxD) mxD = dix, pos = x;
  for (register int i = head[x]; i; i = nxt[i]) {
    int vv = v[i];
    if (vv == fa || fc[vv]) continue;
    dfsTrD(vv, dix + w[i], x);
  }
}
double GetTrD(int x) {
  pos = mxD = 0;
  dfsTrD(x, 0, 0);
  mxD = 0;
  dfsTrD(pos, 0, 0);
  return mxD;
}
double pre[N], bck[N], bs1[N], bs2[N], Ds = 0;
void DP() {
  Ds = mxD = 0;
  for (register int i = 1; i <= tot; ++i) {
    pre[i] = max(pre[i - 1], dmx[cr[i]] + Ds);
    if (i >= 2) bs1[i] = max(bs1[i - 1], mxD + Ds + dmx[cr[i]]);
    mxD = max(mxD, dmx[cr[i]] - Ds);
    Ds += crD[i];
  }
  Ds = mxD = 0;
  crD[0] = crD[tot];
  for (register int i = tot; i >= 1; --i) {
    bck[i] = max(bck[i + 1], dmx[cr[i]] + Ds);
    if (i <= tot - 1) bs2[i] = max(bs2[i + 1], mxD + Ds + dmx[cr[i]]);
    mxD = max(mxD, dmx[cr[i]] - Ds);
    Ds += crD[i - 1];
  }
  Fn = bs1[tot];
  for (register int i = 1; i <= tot - 1; ++i) {
    double mx1 = max(bs1[i], bs2[i + 1]);
    double mx2 = max(mx1, pre[i] + bck[i + 1] + crD[0]);
    Fn = min(Fn, max(mx1, mx2));
  }
}
int main() {
  read(n);
  for (register int i = 1; i <= n; ++i) {
    read(x);
    read(y);
    read(z);
    add(x, y, z);
  }
  dfsCir(1, 0);
  for (register int i = 1; i <= tot; ++i) {
    fc[cr[i]] = 0;
    dia[cr[i]] = GetTrD(cr[i]);
    fc[cr[i]] = 1;
  }
  for (register int i = 1; i <= tot; ++i) {
    mxD = 0;
    dfsTrD(cr[i], 0, 0);
    dmx[cr[i]] = mxD;
  }
  DP();
  for (register int i = 1; i <= tot; ++i) Fn = max(Fn, dia[cr[i]]);
  printf("%lld", (long long)Fn);
  return 0;
}
