#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
const long long INF = 1e15;
multiset<pair<long long, int>, greater<pair<long long, int> > > set1;
multiset<pair<long long, int>, greater<pair<long long, int> > > set2;
struct Edge {
  int to, nxt, w;
} edge[MAXN + 5 << 1];
long long ans, mxdis[MAXN + 5], sum[MAXN + 5 << 1], dia;
int fir[MAXN + 5], ecnt, pre[MAXN + 5], eid[MAXN + 5], lpcnt, dfn[MAXN + 5],
    timer, n;
pair<int, int> lop[MAXN + 5 << 1];
bool inl[MAXN + 5];
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  x *= f;
}
void addedge(int u, int v, int w) {
  edge[++ecnt].to = v;
  edge[ecnt].nxt = fir[u];
  edge[ecnt].w = w;
  fir[u] = ecnt;
}
void getloop(int u) {
  dfn[u] = ++timer;
  for (int e = fir[u]; e && !lpcnt; e = edge[e].nxt) {
    int v = edge[e].to;
    if (v == pre[u]) continue;
    if (dfn[v]) {
      if (dfn[v] < dfn[u]) continue;
      for (int i = v; i != u; i = pre[i]) {
        lop[++lpcnt] = make_pair(i, edge[eid[i]].w);
        inl[i] = true;
      }
      lop[++lpcnt] = make_pair(u, edge[e].w);
      inl[u] = true;
      return;
    }
    pre[v] = u;
    eid[v] = e;
    getloop(v);
  }
}
void dfs(int u, int fa) {
  long long maxx = 0, minx = 0;
  mxdis[u] = 0;
  for (int e = fir[u]; e; e = edge[e].nxt) {
    int v = edge[e].to;
    if (v == fa || inl[v]) continue;
    dfs(v, u);
    mxdis[u] = max(mxdis[u], mxdis[v] + edge[e].w);
    if (mxdis[v] + edge[e].w > maxx) {
      minx = maxx;
      maxx = mxdis[v] + edge[e].w;
    } else if (mxdis[v] + edge[e].w > minx)
      minx = mxdis[v] + edge[e].w;
  }
  dia = max(dia, minx + maxx);
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    int u, v, w;
    read(u), read(v), read(w);
    addedge(u, v, w);
    addedge(v, u, w);
  }
  getloop(1);
  for (int i = 1; i <= lpcnt; ++i) {
    lop[i + lpcnt] = lop[i];
    dfs(lop[i].first, 0);
  }
  for (int i = 2; i <= lpcnt << 1; ++i) sum[i] = sum[i - 1] + lop[i - 1].second;
  for (int i = 1; i <= lpcnt; ++i) {
    set1.insert(make_pair(mxdis[lop[i].first] + sum[i], i));
    set2.insert(make_pair(mxdis[lop[i].first] - sum[i], i));
  }
  ans = INF;
  for (int i = 1; i <= lpcnt; ++i) {
    long long diameter;
    if (set1.begin()->second == set2.begin()->second) {
      multiset<pair<long long, int>, greater<pair<long long, int> > >::iterator
          ptr = set2.begin();
      ++ptr;
      diameter = set1.begin()->first + ptr->first;
      ptr = set1.begin();
      ++ptr;
      diameter = max(diameter, ptr->first + set2.begin()->first);
    } else
      diameter = set1.begin()->first + set2.begin()->first;
    ans = min(ans, diameter);
    set1.erase(make_pair(mxdis[lop[i].first] + sum[i], i));
    set2.erase(make_pair(mxdis[lop[i].first] - sum[i], i));
    set1.insert(
        make_pair(mxdis[lop[i + lpcnt].first] + sum[i + lpcnt], i + lpcnt));
    set2.insert(
        make_pair(mxdis[lop[i + lpcnt].first] - sum[i + lpcnt], i + lpcnt));
  }
  printf("%lld\n", max(ans, dia));
}
