#include <bits/stdc++.h>
using namespace std;
const long long inf = 10000000000000005;
int n, head[500005], nxt[500005], to[500005], edge[500005], num, incir[500005],
    inum, sta[500005], top, valsta[500005];
long long res[500005], Max, val[500005], sum[500005], pre[500005], suf[500005],
    ans, Pre[500005], Suf[500005];
bool in_sta[500005], flag;
inline int read();
inline void add(int, int, int);
inline void get_cir(int, int);
inline void DP(int, int, int, int);
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    int u = read(), v = read(), w = read();
    add(u, v, w), add(v, u, w);
  }
  get_cir(1, 0);
  for (int i = 1; i <= inum; ++i) {
    if (i == 1) {
      DP(incir[i], incir[i + 1], incir[inum], 0);
      continue;
    }
    if (i == inum) {
      DP(incir[inum], incir[inum - 1], incir[1], 0);
      continue;
    }
    DP(incir[i], incir[i - 1], incir[i + 1], 0);
  }
  for (int i = 1; i <= inum; ++i) sum[i] = sum[i - 1] + val[i];
  for (int i = 1; i <= inum; ++i) pre[i] = sum[i - 1] + res[incir[i]];
  for (int i = 1; i <= inum; ++i) pre[i] = max(pre[i], pre[i - 1]);
  for (int i = inum; i >= 1; --i)
    suf[i] = sum[inum] - sum[i - 1] + res[incir[i]];
  for (int i = inum; i >= 1; --i) suf[i] = max(suf[i], suf[i + 1]);
  long long now = 0;
  for (int i = 1; i <= inum; ++i) {
    Pre[i] = max(Pre[i], res[incir[i]] + now + val[i - 1]);
    now = max(res[incir[i]], now + val[i - 1]);
  }
  Suf[inum] = res[incir[inum]];
  now = res[incir[inum]];
  for (int i = inum - 1; i >= 1; --i) {
    Suf[i] = max(Suf[i], res[incir[i]] + now + val[i]);
    now = max(res[incir[i]], now + val[i]);
  }
  for (int i = 1; i <= inum; ++i) Pre[i] = max(Pre[i], Pre[i - 1]);
  for (int i = inum; i >= 1; --i) Suf[i] = max(Suf[i], Suf[i + 1]);
  long long temp = 0;
  ans = inf;
  for (int i = 1; i <= inum; ++i) {
    temp = Max;
    temp = max(temp, Pre[i]);
    temp = max(temp, Suf[i + 1]);
    long long tmp = 0;
    tmp = pre[i] + suf[i + 1];
    temp = max(temp, tmp);
    ans = min(ans, temp);
  }
  printf("%lld\n", ans);
  return 0;
}
inline int read() {
  int x = 0, t = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') (ch == '-') && (t = -1), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
  return x * t;
}
inline void add(int u, int v, int w) {
  nxt[++num] = head[u], head[u] = num, to[num] = v, edge[num] = w;
}
inline void get_cir(int x, int fa) {
  sta[++top] = x;
  in_sta[x] = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    if (flag) return;
    int v = to[i];
    if (v == fa) continue;
    if (!in_sta[v]) {
      valsta[top] = edge[i];
      get_cir(v, x);
    } else {
      flag = true;
      while (top && sta[top] != v)
        incir[++inum] = sta[top], val[inum] = valsta[top - 1], --top;
      incir[++inum] = v, val[inum] = edge[i];
      return;
    }
    in_sta[sta[top]] = 0;
    --top;
  }
}
inline void DP(int x, int mis1, int mis2, int fa) {
  for (int i = head[x]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa) continue;
    if (v == mis1 || v == mis2) continue;
    DP(v, mis1, mis2, x);
    Max = max(Max, res[x] + res[v] + edge[i]);
    res[x] = max(res[x], res[v] + edge[i]);
  }
}
