#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 7, inf = 1e16;
struct Edge {
  long long to, w, nxt;
};
Edge edge[maxn << 1];
long long n, cnt, tot, ans;
long long head[maxn], fa[maxn], inring[maxn], ring[maxn], sum[maxn], dp[maxn],
    ll[maxn], l[maxn], rr[maxn], r[maxn];
void addedge(long long u, long long v, long long w) {
  cnt++;
  edge[cnt].to = v;
  edge[cnt].w = w;
  edge[cnt].nxt = head[u];
  head[u] = cnt;
}
void dfs(long long u, long long father) {
  fa[u] = father;
  for (long long i = head[u]; ~i; i = edge[i].nxt) {
    long long v = edge[i].to;
    if (v == father) continue;
    if (fa[v]) {
      if (tot) continue;
      long long uu = u;
      while (1) {
        inring[uu] = true;
        ring[++tot] = uu;
        if (uu == v) break;
        uu = fa[uu];
      }
      tot = 0;
    } else
      dfs(v, u);
    if (inring[u] && inring[v]) sum[++tot] = sum[tot - 1] + edge[i].w;
  }
}
void dfs1(long long u, long long F) {
  dp[u] = 0;
  for (long long i = head[u]; ~i; i = edge[i].nxt) {
    long long t = edge[i].to;
    if (inring[t] || t == F) continue;
    dfs1(t, u);
    ans = max(ans, dp[t] + dp[u] + edge[i].w);
    dp[u] = max(dp[u], dp[t] + edge[i].w);
  }
}
void init() {
  cnt = tot = 0;
  memset(head, -1, sizeof(head));
  memset(inring, false, sizeof(inring));
}
signed main() {
  init();
  scanf("%lld", &n);
  for (long long i = 1, u, v, w; i <= n; i++) {
    scanf("%lld%lld%lld", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
  }
  dfs(1, -1);
  for (long long i = 1; i <= tot; i++) dfs1(ring[i], -1);
  long long mx = -inf;
  ll[0] = l[0] = -inf;
  for (long long i = 1; i <= tot; i++) {
    l[i] = max(l[i - 1], dp[ring[i]] + sum[i] + mx);
    ll[i] = max(ll[i - 1], dp[ring[i]] + sum[i] + sum[tot]);
    mx = max(mx, dp[ring[i]] - sum[i]);
  }
  rr[tot + 1] = r[tot + 1] = mx = -inf;
  for (long long i = tot; i; i--) {
    r[i] = max(r[i + 1], dp[ring[i]] - sum[i] + mx);
    rr[i] = max(rr[i + 1], dp[ring[i]] - sum[i]);
    mx = max(mx, dp[ring[i]] + sum[i]);
  }
  long long res = inf;
  for (long long i = 1; i <= tot; i++)
    res = min(res, max(ll[i - 1] + rr[i], max(l[i - 1], r[i])));
  printf("%I64d", max(res, ans));
}
