#include <bits/stdc++.h>
namespace FastIO {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
inline void wrap() {
  *oS++ = '\n';
  if (oS == oT) flush();
}
template <class I>
inline void gi(I &x) {
  I sign = 1;
  for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-') sign = -1;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  x *= sign;
}
inline int gi() {
  int x, sign = 1;
  for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-') sign = -1;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  return x * sign;
}
inline long long gl() {
  long long x, sign = 1;
  for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-') sign = -1;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  return x * sign;
}
template <class I>
inline void print(I &x) {
  if (!x) putc('0');
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
}
template <class I>
inline void println(I &x) {
  if (!x) putc('0');
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
  wrap();
}
}  // namespace FastIO
using namespace std;
struct Edge {
  int next, to, w;
} e[2 * 200000 + 5];
int n, head[200000 + 5], eid, tot, a[2 * 200000 + 5], stk[200000 + 5], top,
    vis[200000 + 5], incircle[200000 + 5];
long long f[2 * 200000 + 5], g[2][200000 + 5], sum[2 * 200000 + 5], ans0, ans;
pair<pair<int, int>, int> e0[200000 + 5];
map<pair<int, int>, int> l;
void addEdge(int from, int to, int w) {
  e[++eid].next = head[from];
  e[eid].to = to;
  e[eid].w = w;
  head[from] = eid;
}
int dfs(int u, int pa) {
  if (vis[u]) {
    a[++tot] = u, incircle[u] = 1;
    while (stk[top] != u) a[++tot] = stk[top--], incircle[a[tot]] = 1;
    return 1;
  }
  vis[u] = 1;
  stk[++top] = u;
  for (int i = head[u], v; i; i = e[i].next) {
    v = e[i].to;
    if (v == pa) continue;
    if (dfs(v, u)) return 1;
  }
  top--;
  return 0;
}
void dp(int u, int pa) {
  for (int i = head[u], v, w; i; i = e[i].next) {
    v = e[i].to, w = e[i].w;
    if (v == pa || (incircle[u] && incircle[v])) continue;
    dp(v, u);
    if (g[0][v] + w >= g[0][u])
      g[1][u] = g[0][u], g[0][u] = g[0][v] + w;
    else
      g[1][u] = max(g[1][u], g[0][v] + w);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y, z; i <= n; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    addEdge(x, y, z), addEdge(y, x, z);
    l[make_pair(x, y)] = l[make_pair(y, x)] = z;
    e0[i] = make_pair(make_pair(x, y), z);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; ++i)
    if (incircle[i]) dp(i, 0);
  for (int i = 1; i <= n; ++i) ans0 = max(ans0, g[0][i] + g[1][i]);
  for (int i = 1; i <= tot; ++i) a[i + tot] = a[i];
  for (int i = 1; i <= 2 * tot; ++i) {
    sum[i] = sum[i - 1] + l[make_pair(a[i], a[i - 1])];
    f[i] = g[0][a[i]];
  }
  set<pair<long long, int>> s1, s2;
  for (int i = 1; i < tot; ++i) {
    s1.insert(make_pair(f[i] - sum[i], i));
    s2.insert(make_pair(f[i] + sum[i], i));
  }
  ans = 0x3f3f3f3f3f3f3f3fLL;
  for (int i = tot; i < 2 * tot; ++i) {
    s1.insert(make_pair(f[i] - sum[i], i));
    s2.insert(make_pair(f[i] + sum[i], i));
    auto p1 = s1.end(), p2 = s2.end();
    p1--, p2--;
    long long t;
    if (p1->second != p2->second)
      t = p1->first + p2->first;
    else {
      long long k = p2->first;
      p2--;
      t = p1->first + p2->first;
      p1--;
      t = max(t, p1->first + k);
    }
    s1.erase(make_pair(f[i - tot + 1] - sum[i - tot + 1], i - tot + 1));
    s2.erase(make_pair(f[i - tot + 1] + sum[i - tot + 1], i - tot + 1));
    ans = min(ans, max(ans0, t));
  }
  printf("%lld\n", ans);
  return 0;
}
