#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2e5 + 7;
const long long INF = -0x3f3f3f3f3f3f3f3f;
struct edge {
  long long to;
  long long next;
  long long val;
} e[MAX << 2];
long long eid = 0, head[MAX];
void adde(long long x, long long y, long long w) {
  e[++eid].to = y;
  e[eid].next = head[x];
  e[eid].val = w;
  head[x] = eid;
}
long long cnt_circle, phi;
long long one_i[MAX], i_n[MAX], sum_wgt[MAX], circle[MAX], vis[MAX], lft[MAX],
    rgt[MAX], dp[MAX];
long long get_circle(long long u, long long lst) {
  if (vis[u])
    return u;
  else {
    vis[u] = 2;
  }
  for (long long i = head[u]; i; i = e[i].next) {
    long long v = e[i].to;
    if (v == lst) continue;
    long long tmp = get_circle(v, u);
    if (tmp) {
      circle[++cnt_circle] = u;
      vis[u] = 1;
      sum_wgt[cnt_circle] = e[i].val;
      if (tmp == u) {
        return 0;
      } else
        return tmp;
    }
  }
  return 0;
}
void get_phi(long long u, long long lst) {
  for (long long i = head[u]; i; i = e[i].next) {
    if (vis[e[i].to] != 1 && e[i].to != lst) {
      get_phi(e[i].to, u);
      phi = max(phi, dp[u] + dp[e[i].to] + e[i].val);
      dp[u] = max(dp[u], dp[e[i].to] + e[i].val);
    }
  }
}
signed main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long fr, to, w;
    cin >> fr >> to >> w;
    adde(fr, to, w);
    adde(to, fr, w);
  }
  get_circle(1, -1);
  sum_wgt[0] = 0;
  for (long long i = 1; i <= cnt_circle; i++) {
    get_phi(circle[i], -1);
    sum_wgt[i] += sum_wgt[i - 1];
  }
  long long tmp = INF;
  lft[0] = one_i[0] = INF;
  for (long long i = 1; i <= cnt_circle; i++) {
    one_i[i] = max(one_i[i - 1], dp[circle[i]] + sum_wgt[i] + tmp);
    lft[i] = max(lft[i - 1], dp[circle[i]] + sum_wgt[i]);
    tmp = max(tmp, dp[circle[i]] - sum_wgt[i]);
  }
  tmp = INF;
  rgt[cnt_circle + 1] = i_n[cnt_circle + 1] = INF;
  for (long long i = cnt_circle; i >= 1; i--) {
    i_n[i] = max(i_n[i + 1], dp[circle[i]] - sum_wgt[i] + tmp);
    rgt[i] = max(rgt[i + 1], dp[circle[i]] + sum_wgt[cnt_circle] - sum_wgt[i]);
    tmp = max(tmp, dp[circle[i]] + sum_wgt[i]);
  }
  long long answer = -INF;
  for (long long i = 1; i <= cnt_circle; i++) {
    long long tmp = max(i_n[i], one_i[i - 1]);
    answer = min(answer, max(tmp, lft[i - 1] + rgt[i]));
  }
  cout << max(answer, phi) << endl;
}
