#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1LL;
  long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = mul(_ret, _a, _mod);
  return _ret;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0LL;
  long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = add(_ret, _a, _mod);
  return _ret;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
long long mx[202020 << 3], lft[202020 << 3], rgt[202020 << 3];
void modify(int no, int l, int r, int p, long long tl = 10000000000000000LL,
            long long tr = -10000000000000000LL) {
  if (l == r) {
    lft[no] = tl;
    rgt[no] = tr;
    mx[no] = 0;
    return;
  }
  if (p <= ((l + r) >> 1))
    modify((no << 1), l, ((l + r) >> 1), p, tl, tr);
  else
    modify((1 + (no << 1)), ((l + r) >> 1) + 1, r, p, tl, tr);
  lft[no] = min(lft[(no << 1)], lft[(1 + (no << 1))]);
  rgt[no] = max(rgt[(no << 1)], rgt[(1 + (no << 1))]);
  mx[no] = max(max(mx[(no << 1)], mx[(1 + (no << 1))]),
               rgt[(1 + (no << 1))] - lft[(no << 1)]);
}
void build() {}
int n, p[202020], deg[202020];
vector<pair<int, int> > v[202020], s[202020];
void init() {
  n = getint();
  for (int i = 0; i < n; i++) {
    int ui = getint();
    int vi = getint();
    int li = getint();
    v[ui].push_back({vi, li});
    v[vi].push_back({ui, li});
    deg[ui]++;
    deg[vi]++;
  }
}
bool gt[202020];
vector<int> cycle;
long long dst[202020], tot, gg[202020], gb;
long long dp(int now) {
  long long tmx = 0;
  for (auto e : s[now]) {
    long long ret = dp(e.first) + e.second;
    gb = max(gb, tmx + ret);
    tmx = max(tmx, ret);
  }
  return tmx;
}
void gogo(int now, long long dd) {
  gt[now] = true;
  dst[now] = dd;
  cycle.push_back(now);
  for (auto i : v[now]) {
    if (gt[i.first]) {
      if (dd == 0 and i.first == cycle.back()) tot = dst[i.first] + i.second;
      continue;
    }
    gogo(i.first, dd + i.second);
  }
}
void solve() {
  queue<int> Q;
  for (int i = 1; i <= n; i++)
    if (deg[i] == 1) {
      Q.push(i);
      gt[i] = true;
    }
  while (Q.size()) {
    int tn = Q.front();
    Q.pop();
    for (auto e : v[tn]) {
      if (gt[e.first]) continue;
      p[tn] = e.first;
      s[p[tn]].push_back({tn, e.second});
      deg[e.first]--;
      if (deg[e.first] == 1) {
        Q.push(e.first);
        gt[e.first] = true;
      }
    }
  }
  int who = 0;
  for (int i = 1; i <= n and !who; i++)
    if (!p[i]) who = i;
  gogo(who, 0);
  for (auto pp : cycle) gg[pp] = dp(pp);
  int csz = (int)cycle.size();
  for (int i = 0; i < csz; i++) {
    int now = cycle[i];
    modify(1, 0, csz + csz - 1, i, dst[now] - gg[now], dst[now] + gg[now]);
  }
  for (int i = csz; i < csz + csz; i++) modify(1, 0, csz + csz - 1, i);
  long long bst = mx[1];
  for (int i = 0; i < csz; i++) {
    int now = cycle[i];
    modify(1, 0, csz + csz - 1, i);
    modify(1, 0, csz + csz - 1, i + csz, dst[now] + tot - gg[now],
           dst[now] + tot + gg[now]);
    bst = min(bst, mx[1]);
  }
  printf("%lld\n", max(bst, gb));
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}
