#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long N = 2e5 + 100;
set<pair<long long, long long> > g[N];
bool used[N];
vector<long long> cycle, len;
long long h[N], l[N], r[N];
long long find_cycle(long long v, long long p) {
  if (used[v]) return v;
  used[v] = true;
  for (auto to : g[v])
    if (to.first != p) {
      long long res = find_cycle(to.first, v);
      if (res)
        return cycle.push_back(v), len.push_back(to.second), v == res ? 0 : res;
    }
  return 0;
}
pair<long long, long long> far(long long v, long long p) {
  pair<long long, long long> ans(0, v);
  for (auto to : g[v])
    if (to.first != p) {
      pair<long long, long long> res = far(to.first, v);
      res.first += to.second;
      ans = max(ans, res);
    }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long u, v, l;
    cin >> u >> v >> l;
    g[u].insert({v, l});
    g[v].insert({u, l});
  }
  find_cycle(1, 0);
  long long k = cycle.size();
  for (long long i = 0; i < k; i++)
    g[cycle[i]].erase(g[cycle[i]].lower_bound(
        pair<long long, long long>(cycle[(i + 1) % k], 0))),
        g[cycle[(i + 1) % k]].erase(g[cycle[(i + 1) % k]].lower_bound(
            pair<long long, long long>(cycle[i], 0)));
  long long ans1 = 0, mx = 0;
  for (long long i = 0; i < k; i++) {
    long long v;
    tie(h[i], v) = far(cycle[i], 0);
    ans1 = max(ans1, far(v, 0).first);
    if (h[i] > h[mx]) mx = i;
  }
  for (long long i = (mx + 1) % k, j = mx; i != mx; j = i, i = (i + 1) % k)
    r[i] = r[j] + len[i];
  for (long long i = 0; i < k; i++)
    if (i != mx) r[i] += h[i];
  for (long long i = (mx + 1) % k, j = mx; i != mx; j = i, i = (i + 1) % k)
    r[i] = max(r[i], r[j]);
  for (long long i = (mx - 1 + k) % k, j = mx; i != mx;
       j = i, i = (i - 1 + k) % k)
    l[i] = l[j] + len[j];
  for (long long i = 0; i < k; i++)
    if (i != mx) l[i] += h[i];
  for (long long i = (mx - 1 + k) % k, j = mx; i != mx;
       j = i, i = (i - 1 + k) % k)
    l[i] = max(l[i], l[j]);
  long long ans2 = 1e18;
  for (long long i = 0, j = k - 1; i < k; j = i, i++)
    ans2 = min(ans2, max({l[i] + r[j], l[i] + h[mx], h[mx] + r[j]}));
  cout << max(ans1, ans2);
}
