#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar();
  return X * w;
}
const long long N = 400000 + 10;
long long n;
struct Edge {
  long long v, w, nxt;
} e[N << 1];
long long head[N];
inline void addEdge(long long u, long long v, long long w) {
  static long long cnt = 0;
  e[++cnt] = (Edge){v, w, head[u]}, head[u] = cnt;
}
long long eid[N], in[N], fa[N];
long long dfn[N], tim = 0, top = 0;
pair<long long, long long> cir[N];
long long f[N], mx;
long long sum[N];
set<pair<long long, long long>, greater<pair<long long, long long> > > s1, s2;
inline void find_circle(long long u) {
  dfn[u] = ++tim;
  for (register long long i = head[u]; i; i = e[i].nxt) {
    long long v = e[i].v;
    if (v == fa[u]) continue;
    if (dfn[v]) {
      if (dfn[v] < dfn[u]) continue;
      for (register long long i = v; i != u; i = fa[i])
        cir[++top] = make_pair(i, e[eid[i]].w), in[i] = 1;
      cir[++top] = make_pair(u, e[i].w), in[u] = 1;
      return;
    }
    fa[v] = u, eid[v] = i;
    find_circle(v);
    if (top) return;
  }
}
inline void dfs(long long u, long long fa) {
  f[u] = 0;
  long long mx1 = 0, mx2 = 0;
  for (register long long i = head[u]; i; i = e[i].nxt) {
    long long v = e[i].v, w = e[i].w;
    ;
    if (v == fa || in[v]) continue;
    dfs(v, u);
    f[u] = max(f[u], f[v] + w);
    if (f[v] + w > mx1)
      mx2 = mx1, mx1 = f[v] + w;
    else if (f[v] + w > mx2)
      mx2 = f[v] + w;
  }
  mx = max(mx, mx1 + mx2);
}
signed main() {
  n = read();
  for (register long long i = 1; i <= n; ++i) {
    long long u = read(), v = read(), w = read();
    addEdge(u, v, w), addEdge(v, u, w);
  }
  find_circle(1);
  for (register long long i = 1; i <= top; ++i)
    cir[i + top] = cir[i], dfs(cir[i].first, 0);
  for (register long long i = 2; i <= top * 2; ++i)
    sum[i] = sum[i - 1] + cir[i - 1].second;
  for (register long long i = 1; i <= top; ++i) {
    s1.insert(make_pair(f[cir[i].first] + sum[i], i));
    s2.insert(make_pair(f[cir[i].first] - sum[i], i));
  }
  long long ans = 1e18;
  for (register long long i = 1; i <= top; ++i) {
    long long now;
    if (s1.begin()->second == s2.begin()->second) {
      multiset<pair<long long, long long>,
               greater<pair<long long, long long> > >::iterator it = s1.begin();
      ++it;
      now = it->first + s2.begin()->first;
      it = s2.begin();
      ++it;
      now = max(now, it->first + s1.begin()->first);
    } else
      now = s1.begin()->first + s2.begin()->first;
    ans = min(ans, now);
    s1.erase(make_pair(f[cir[i].first] + sum[i], i));
    s2.erase(make_pair(f[cir[i].first] - sum[i], i));
    s1.insert(make_pair(f[cir[i + top].first] + sum[i + top], i + top));
    s2.insert(make_pair(f[cir[i + top].first] - sum[i + top], i + top));
  }
  printf("%I64d\n", max(ans, mx));
  return 0;
}
