#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int NMAX = 200666;
const long long INF = 3000000000000000666;
const long long maxv = 100000;
vector<int> G[NMAX];
vector<long long> C[NMAX];
int cyc[NMAX];
int viz[NMAX];
int prv[NMAX];
int nxt[NMAX];
long long dpsuf[NMAX];
long long srt[NMAX];
long long dppre[NMAX];
long long srt1suf[NMAX];
long long srt1pre[NMAX];
long long lhtcw[NMAX], lhtccw[NMAX];
long long val[NMAX];
int n, k;
int dfs(int v, int p) {
  if (viz[v]) {
    viz[v]++;
    cyc[++k] = v;
    return 2;
  }
  viz[v]++;
  for (int i = 0; i < G[v].size(); ++i) {
    int el = G[v][i];
    if (el != p) {
      if (dfs(el, v) && viz[v] != 2) {
        lhtcw[k] = C[v][i];
        cyc[++k] = v;
        return 2;
      }
      if (viz[v] == 2) {
        lhtcw[k] = C[v][i];
        return 0;
      }
    }
  }
  return 0;
}
long long depth(int v, int a, int b) {
  long long mx = 0;
  for (int i = 0; i < G[v].size(); ++i) {
    int el = G[v][i];
    if (el != a && el != b) {
      mx = max(mx, depth(el, v, 0) + C[v][i]);
    }
  }
  return mx;
}
int igna, ignb;
pair<long long, int> far(int v, int p) {
  long long mx = 0;
  int mxi = v;
  for (int i = 0; i < G[v].size(); ++i) {
    int el = G[v][i];
    if ((igna == el && ignb == v) || ((ignb == el && igna == v)) || el == p)
      continue;
    pair<long long, int> gt = far(el, v);
    if (gt.first + C[v][i] > mx) {
      mx = gt.first + C[v][i];
      mxi = gt.second;
    }
  }
  return {mx, mxi};
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    G[l].push_back(r);
    G[r].push_back(l);
    C[l].push_back(c);
    C[r].push_back(c);
  }
  dfs(1, 0);
  for (int i = 1; i <= k; ++i) {
    nxt[i] = i + 1;
    prv[i] = i - 1;
  }
  nxt[k] = 1;
  prv[1] = k;
  for (int i = 1; i <= k; ++i) {
    val[i] = depth(cyc[i], cyc[nxt[i]], cyc[prv[i]]);
  }
  for (int i = 2; i <= k; ++i) {
    lhtccw[i] = lhtcw[i - 1];
  }
  lhtccw[1] = lhtcw[k];
  for (int i = 1; i <= k; ++i) {
  }
  dppre[1] = val[1];
  long long cur_far = -INF;
  for (int i = 2; i <= k; ++i) {
    cur_far = max(cur_far, val[i - 1]) + lhtcw[i - 1];
    dppre[i] = max(dppre[i - 1], val[i] + cur_far);
  }
  srt1pre[1] = val[1];
  long long ss = 0;
  for (int i = 2; i <= k; ++i) {
    ss += lhtcw[i - 1];
    srt1pre[i] = max(srt1pre[i - 1], ss + val[i]);
  }
  memset(srt, 0, sizeof(srt));
  dpsuf[k + 1] = -INF;
  cur_far = -INF;
  for (int i = k; i >= 2; --i) {
    cur_far = max(cur_far, val[i + 1]) + lhtcw[i];
    dpsuf[i] = max(dpsuf[i + 1], cur_far + val[i]);
  }
  srt1suf[k + 1] = -INF;
  ss = 0;
  for (int i = k; i >= 2; --i) {
    ss += lhtcw[i];
    srt1suf[i] = max(srt1suf[i + 1], ss + val[i]);
  }
  long long rs = INF;
  int rse = 0;
  dpsuf[k + 1] = -INF;
  srt1suf[k + 1] = -INF;
  for (int i = 1; i <= k; ++i) {
    long long mx =
        max(dppre[i], max(dpsuf[i + 1], srt1pre[i] + srt1suf[i + 1]));
    if (mx < rs) {
      rs = mx;
      rse = i;
    }
  }
  igna = cyc[rse];
  ignb = cyc[nxt[rse]];
  int far1 = far(1, 0).second;
  cout << far(far1, 0).first << "\n";
}
int main() {
  cout << setprecision(10) << fixed;
  ios_base::sync_with_stdio(0);
  solve();
  return 0;
}
