#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 4e5 + 10;
int in[MAXN], top, fa[MAXN], dfn[MAXN], eid[MAXN], tot;
long long dp[MAXN], sum[MAXN], mx;
pair<long long, long long> cir[MAXN];
int n, head[MAXN], cnt;
set<pair<long long, long long>, greater<pair<long long, long long>>> s1, s2;
struct Edge {
  int v, next;
  long long w;
} edge[MAXN * 2];
void add(int u, int v, int w) {
  cnt++;
  edge[cnt].v = v;
  edge[cnt].w = w;
  edge[cnt].next = head[u];
  head[u] = cnt;
}
void find(int u) {
  dfn[u] = ++tot;
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].v;
    if (v == fa[u]) continue;
    if (dfn[v]) {
      if (dfn[v] < dfn[u]) continue;
      for (int j = v; j != u; j = fa[j])
        cir[++top] = pair<long long, long long>(j, edge[eid[j]].w), in[j] = 1;
      cir[++top] = pair<long long, long long>(u, edge[i].w), in[u] = 1;
      return;
    }
    fa[v] = u;
    eid[v] = i;
    find(v);
    if (top) return;
  }
}
void dfs(int u, int fa) {
  dp[u] = 0;
  long long mx1 = 0, mx2 = 0;
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].v;
    if (v == fa || in[v]) continue;
    dfs(v, u);
    dp[u] = max(dp[u], dp[v] + edge[i].w);
    if (dp[v] + edge[i].w > mx1) {
      mx2 = mx1;
      mx1 = dp[v] + edge[i].w;
    } else if (dp[v] + edge[i].w > mx2) {
      mx2 = dp[v] + edge[i].w;
    }
  }
  mx = max(mx, mx1 + mx2);
}
int main() {
  cin >> n;
  memset(head, -1, sizeof head);
  for (int i = 1; i <= n; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    add(u, v, w);
    add(v, u, w);
  }
  find(1);
  for (int i = 1; i <= top; i++) cir[i + top] = cir[i], dfs(cir[i].first, 0);
  for (int i = 2; i <= top * 2; i++) sum[i] = sum[i - 1] + cir[i - 1].second;
  for (int i = 1; i <= top; i++) {
    s1.insert(pair<long long, long long>(dp[cir[i].first] + sum[i], i));
    s2.insert(pair<long long, long long>(dp[cir[i].first] - sum[i], i));
  }
  long long ans = 1e18;
  for (int i = 1; i <= top; i++) {
    long long now = 0;
    if (s1.begin()->second == s2.begin()->second) {
      auto 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(pair<long long, long long>(dp[cir[i].first] + sum[i], i));
    s2.erase(pair<long long, long long>(dp[cir[i].first] - sum[i], i));
    s1.insert(
        pair<long long, long long>(dp[cir[i + top].first] + sum[i + top], i));
    s2.insert(
        pair<long long, long long>(dp[cir[i + top].first] - sum[i + top], i));
  }
  printf("%lld\n", max(ans, mx));
  return 0;
}
