#include <bits/stdc++.h>
using namespace std;
long long T = 0;
void dfs_tin(long long x, const vector<vector<pair<long long, long long> > > &g,
             vector<long long> &tin, vector<long long> &par) {
  tin[x] = T++;
  for (const auto &pr : g[x])
    if (tin[pr.first] == -1) {
      par[pr.first] = x;
      dfs_tin(pr.first, g, tin, par);
    }
}
long long dfs_depth(long long x, long long p,
                    const vector<vector<pair<long long, long long> > > &g,
                    const vector<char> &used,
                    vector<pair<long long, long long> > &depth) {
  long long d1 = 0, d2 = 0, ans = 0;
  for (const auto &pr : g[x])
    if (pr.first != p && !used[pr.first]) {
      ans = max(ans, dfs_depth(pr.first, x, g, used, depth));
      long long cur = pr.second + depth[pr.first].first;
      if (cur > d1)
        d2 = d1, d1 = cur;
      else if (cur > d2)
        d2 = cur;
    }
  ans = max(ans, d1 + d2);
  depth[x] = make_pair(d1, d2);
  return ans;
}
const long long inf = (long long)1e18;
struct segtree {
  struct info {
    long long l, r;
    long long hr, hl, best;
    info() {
      l = r = -1;
      hr = hl = best = 0;
    }
    bool empty() const { return l == -1; }
    info(long long h, long long l_, long long r_) : l(l_), r(r_) {
      hl = hr = best = h;
    }
  };
  vector<long long> pref;
  vector<info> vals;
  long long tsz;
  info combine(const info &l, const info &r) {
    if (l.empty() || r.empty()) return l.empty() ? r : l;
    assert(l.r == r.l);
    info res;
    res.l = l.l, res.r = r.r;
    res.hr = max(r.hr, l.hr + pref[r.r - 1] - pref[r.l - 1]);
    res.hl = max(l.hl, r.hl + pref[l.r] - pref[l.l]);
    res.best = max(r.best, l.best);
    res.best = max(res.best, l.hr + r.hl + pref[l.r] - pref[l.r - 1]);
    return res;
  }
  segtree(const vector<long long> &h, const vector<long long> &len) {
    pref = vector<long long>((long long)(len).size() + 1);
    for (long long i = 0; i < (long long)((long long)(len).size()); ++i)
      pref[i + 1] = pref[i] + len[i];
    tsz = 1;
    while (tsz < (long long)(h).size()) tsz *= 2;
    vals.resize(2 * tsz);
    for (long long i = 0; i < (long long)((long long)(h).size()); ++i)
      vals[i + tsz] = info(h[i], i, i + 1);
    for (long long i = ((long long)(tsz)-1); i >= 0; --i)
      if (i) vals[i] = combine(vals[2 * i], vals[2 * i + 1]);
  }
  info query(long long l, long long r) {
    info ansl, ansr;
    for (l += tsz, r += tsz; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ansl = combine(ansl, vals[l++]);
      if (r & 1) ansr = combine(vals[--r], ansr);
    }
    return combine(ansl, ansr);
  }
};
void solve(long long n) {
  vector<vector<pair<long long, long long> > > g(n);
  map<pair<long long, long long>, long long> cost;
  for (long long i = 0; i < (long long)(n); ++i) {
    long long x, y, l;
    cin >> x >> y >> l;
    --x, --y;
    cost[make_pair(x, y)] = cost[make_pair(y, x)] = l;
    g[x].push_back(make_pair(y, l));
    g[y].push_back(make_pair(x, l));
  }
  T = 0;
  vector<long long> tin(n, -1), par(n, -1);
  dfs_tin(0, g, tin, par);
  vector<long long> cycle;
  for (long long i = 0; i < (long long)(n); ++i)
    if (cycle.empty()) {
      for (const auto &pr : g[i])
        if (tin[pr.first] < tin[i] && pr.first != par[i]) {
          long long u = i, v = pr.first;
          while (u != par[v]) cycle.push_back(u), u = par[u];
        }
    }
  assert(!cycle.empty());
  vector<char> used(n);
  for (long long v : cycle) used[v] = 1;
  long long ans = 0;
  vector<pair<long long, long long> > depth(n);
  for (long long v : cycle) ans = max(ans, dfs_depth(v, -1, g, used, depth));
  const long long m = (long long)(cycle).size();
  vector<long long> h(2 * m);
  vector<long long> len(2 * m - 1);
  for (long long i = 0; i < (long long)(2 * m); ++i) {
    h[i] = depth[cycle[i % m]].first;
    if (i < (long long)(len).size())
      len[i] = cost.at(make_pair(cycle[i % m], cycle[(i + 1) % m]));
  }
  segtree data(h, len);
  long long best = inf;
  for (long long i = 0; i < (long long)(m); ++i) {
    best = min(best, data.query(i, i + m).best);
  }
  ans = max(ans, best);
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  while (cin >> n) solve(n);
}
