#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, next;
  int w;
} edge[200100 << 1];
int head[200100], tot;
void addedge(int u, int v, int w) {
  edge[tot].to = v;
  edge[tot].next = head[u];
  edge[tot].w = w;
  head[u] = tot++;
}
void init() {
  memset(head, -1, sizeof(head));
  tot = 0;
}
int n;
int sta[200100], ri, bian[200100];
int p[200100];
int lop[200100], siz;
int to[200100];
void dfs1(int u, int pre) {
  sta[++ri] = u;
  p[u] = ri;
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == pre) continue;
    if (p[v]) {
      for (int j = p[v]; j <= ri; ++j) {
        lop[siz] = sta[j];
        to[siz] = bian[j];
        siz++;
      }
      to[siz - 1] = edge[i].w;
      return;
    }
    bian[ri] = edge[i].w;
    dfs1(v, u);
    if (siz) return;
  }
  ri--;
  p[u] = 0;
}
long long dep[200100];
void dfs2(int rt, int u, long long d, int p1, int p2) {
  dep[rt] = max(dep[rt], d);
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == p1 || v == p2) continue;
    dfs2(rt, v, d + edge[i].w, u, u);
  }
}
long long pref1[200100], suff1[200100];
long long pref2[200100], suff2[200100];
int ban1, ban2;
long long dist[200100];
void dfs3(int u, int pre, long long d) {
  dist[u] = d;
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == pre) continue;
    if (u == ban1 && v == ban2) continue;
    if (u == ban2 && v == ban1) continue;
    dfs3(v, u, d + edge[i].w);
  }
}
int main() {
  scanf("%d", &n);
  init();
  for (int i = 1; i <= n; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
  }
  dfs1(1, -1);
  for (int i = 0; i < siz; ++i)
    dfs2(i, lop[i], 0, lop[(i + siz - 1) % siz], lop[(i + 1) % siz]);
  pref1[0] = dep[0];
  long long now = 0;
  for (int i = 1; i < siz; ++i) {
    now += to[i - 1];
    pref1[i] = max(pref1[i - 1], now + dep[i]);
  }
  suff1[siz - 1] = dep[siz - 1] + to[siz - 1];
  now = to[siz - 1];
  for (int i = siz - 2; i >= 0; --i) {
    now += to[i];
    suff1[i] = max(suff1[i + 1], now + dep[i]);
  }
  now = dep[0];
  pref2[0] = dep[0];
  for (int i = 1; i < siz; ++i) {
    now += to[i - 1];
    pref2[i] = max(pref2[i - 1], now + dep[i]);
    now = max(now, dep[i]);
  }
  now = dep[siz - 1];
  suff2[siz - 1] = dep[siz - 1];
  for (int i = siz - 2; i >= 0; --i) {
    now += to[i];
    suff2[i] = max(suff2[i + 1], now + dep[i]);
    now = max(now, dep[i]);
  }
  long long Mx = pref2[siz - 1];
  int id = siz - 1;
  for (int i = 0; i < siz - 1; ++i) {
    long long tmp = max(pref1[i] + suff1[i + 1], max(pref2[i], suff2[i + 1]));
    if (tmp < Mx) {
      Mx = tmp;
      id = i;
    }
  }
  ban1 = lop[id], ban2 = lop[(id + 1) % siz];
  dfs3(1, 0, 0);
  int u = 1;
  for (int i = 1; i <= n; ++i)
    if (dist[i] > dist[u]) u = i;
  dfs3(u, 0, 0);
  int v = u;
  for (int i = 1; i <= n; ++i)
    if (dist[i] > dist[v]) v = i;
  printf("%lld\n", dist[v]);
  return 0;
}
