#include <bits/stdc++.h>
using namespace std;
int read();
int n;
int hd[200005], nx[400005], to[400005], w[400005], cnt;
void add(int f, int t, int wei) {
  nx[++cnt] = hd[f], hd[f] = cnt, to[cnt] = t, w[cnt] = wei;
}
int st[200005], vis[200005], top;
int ring[200005], rc;
int onr[200005];
void getring(int u, int lasedge) {
  st[++top] = u, vis[u] = 1;
  for (int i = hd[u]; i; i = nx[i]) {
    int v = to[i];
    if ((((i - 1) ^ 1) + 1 == lasedge) && lasedge) continue;
    if (vis[v]) {
      while (st[top] != v) ring[++rc] = st[top--];
      return ring[++rc] = v, void();
    }
    getring(v, i);
    if (rc) return;
  }
  top--;
}
long long dep[200005], lim;
void dfs(int u, int fa) {
  long long f1 = 0, f2 = 0;
  for (int i = hd[u]; i; i = nx[i]) {
    int v = to[i];
    if (v == fa || onr[v]) continue;
    dfs(v, u), f2 = max(f2, w[i] + dep[v]);
    if (f1 < f2) swap(f1, f2);
  }
  dep[u] = f1, lim = max(f1 + f2, lim);
}
long long pre[200005], suf[200005], d[200005];
long long pr1[200005], pr2[200005], sf1[200005], sf2[200005];
struct P {
  int l;
  long long w;
  int f;
} q[200005];
void work() {
  ring[0] = ring[rc];
  int t = rc == 2;
  for (int i = 1; i <= rc; ++i) {
    d[i] = dep[ring[i]];
    for (int j = hd[ring[i]]; j; j = nx[j])
      if (to[j] == ring[i - 1]) {
        if (t) {
          t = 0;
          continue;
        }
        pre[i] = suf[i - 1] = w[j];
        break;
      }
  }
  for (int i = 1; i <= rc; ++i) pre[i] += pre[i - 1];
  for (int i = rc; i >= 1; --i) suf[i] += suf[i + 1];
  long long mx = -pre[1];
  for (int i = 1; i <= rc; ++i) {
    pr1[i] = max(pr1[i - 1], d[i] + pre[i]);
    pr2[i] = max(pre[i] + d[i] + mx, pr2[i - 1]);
    mx = max(mx, d[i] - pre[i]);
  }
  mx = 0;
  for (int i = rc; i >= 1; --i) {
    sf1[i] = max(sf1[i + 1], d[i] + suf[i]);
    sf2[i] = max(suf[i] + d[i] + mx, sf2[i + 1]);
    mx = max(mx, d[i] - suf[i]);
  }
  long long res = pr2[rc];
  for (int i = 2; i <= rc; ++i)
    res = min(res, max(pr1[i - 1] + sf1[i], max(pr2[i - 1], sf2[i])));
  printf("%lld\n", max(res, lim));
}
int main() {
  n = read();
  for (int i = 1, u, v, w; i <= n; ++i)
    u = read(), v = read(), w = read(), add(u, v, w), add(v, u, w);
  getring(1, 0);
  for (int i = 1; i <= rc; ++i) onr[ring[i]] = i;
  for (int i = 1; i <= rc; ++i) dfs(ring[i], 0);
  if (rc == 1) return printf("%lld\n", dep[ring[1]]), 0;
  work();
  return 0;
}
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
