#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, val, next;
} edge[400001];
int head[200001], cnt;
void add_edge(int u, int v, int w) {
  cnt++;
  edge[cnt].to = v;
  edge[cnt].val = w;
  edge[cnt].next = head[u];
  head[u] = cnt;
  return;
}
int n, tot, Index, dfn[200001];
int a[200001], b[200001], c[200001];
int f[200001];
long long dp[200001];
long long u1[200001], u2[200001], v1[200001], v2[200001];
long long ans1, ans2;
bool ok[200001];
void dfs(int u) {
  dfn[u] = ++Index;
  for (int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == f[u]) continue;
    if (!dfn[v]) {
      f[v] = u;
      c[v] = edge[i].val;
      dfs(v);
    } else if (dfn[v] > dfn[u]) {
      while (v != u) {
        ok[v] = false;
        tot++;
        a[tot] = v;
        b[tot] = c[v];
        v = f[v];
      }
      ok[u] = false;
      tot++;
      a[tot] = u;
      b[tot] = edge[i].val;
    }
  }
  return;
}
void DP(int u, int father) {
  for (int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == father) continue;
    if (!ok[v]) continue;
    DP(v, u);
    ans1 = max(ans1, dp[u] + dp[v] + edge[i].val);
    dp[u] = max(dp[u], dp[v] + edge[i].val);
  }
  return;
}
int main() {
  scanf("%d", &n);
  memset(ok, true, sizeof(ok));
  for (int i = 1; i <= n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    add_edge(x, y, z);
    add_edge(y, x, z);
  }
  dfs(1);
  long long sum = 0, mx = 0;
  for (int i = 1; i <= tot; i++) DP(a[i], 0);
  for (int i = 1; i <= tot; i++) {
    sum += b[i - 1];
    u1[i] = max(u1[i - 1], dp[a[i]] + sum);
    v1[i] = max(v1[i - 1], dp[a[i]] + sum + mx);
    mx = max(mx, dp[a[i]] - sum);
  }
  long long tmp = b[tot];
  sum = mx = b[tot] = 0;
  for (int i = tot; i > 0; i--) {
    sum += b[i];
    u2[i] = max(u2[i + 1], dp[a[i]] + sum);
    v2[i] = max(v2[i + 1], dp[a[i]] + sum + mx);
    mx = max(mx, dp[a[i]] - sum);
  }
  ans2 = v1[tot];
  for (int i = 1; i < tot; i++)
    ans2 = min(ans2, max(max(v1[i], v2[i + 1]), u1[i] + u2[i + 1] + tmp));
  printf("%lld", max(ans1, ans2));
  return 0;
}
