#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
const long long INF = ~0ULL >> 1;
const int maxn = 240000;
int N, x, y, w, C, vis[maxn], cid[maxn], onCircle[maxn];
long long clen, dis[maxn], d[maxn], dia, pre[maxn], suc[maxn], tpre[maxn],
    tsuc[maxn], best = INF;
vector<pair<int, int> > E[maxn];
queue<int> Q;
void dfs(int u, int fa) {
  d[u] = 0;
  long long son[2] = {-INF, -INF};
  for (int i = (0); i < (E[u].size()); ++i)
    if (!onCircle[E[u][i].first] && E[u][i].first != fa) {
      int v = E[u][i].first;
      dfs(v, u);
      d[u] = max(d[u], d[v] + E[u][i].second);
      if (d[v] + E[u][i].second > son[0])
        son[1] = son[0], son[0] = d[v] + E[u][i].second;
      else if (d[v] + E[u][i].second > son[1])
        son[1] = d[v] + E[u][i].second;
    }
  if (son[1] > -INF) dia = max(dia, son[0] + son[1]);
}
int main() {
  scanf("%d", &N);
  for (int i = (1); i <= (N); ++i) {
    scanf("%d%d%d", &x, &y, &w);
    E[x].push_back((make_pair(y, w)));
    E[y].push_back((make_pair(x, w)));
    d[x]++;
    d[y]++;
  }
  for (int i = (1); i <= (N); ++i)
    if (d[i] == 1) Q.push(i);
  while (Q.size()) {
    int u = Q.front();
    Q.pop();
    vis[u] = 1;
    for (int i = (0); i < (E[u].size()); ++i) {
      --d[E[u][i].first];
      if (d[E[u][i].first] == 1) Q.push(E[u][i].first);
    }
  }
  for (int i = (1); i <= (N); ++i)
    if (!vis[i]) {
      int cur = i;
      onCircle[i] = ++C;
      cid[C] = i;
      dis[i] = 0;
      vis[i] = 1;
      do {
        int flag = 0;
        for (int j = (0); j < (E[cur].size()); ++j)
          if (!vis[E[cur][j].first]) {
            flag = 1;
            int v = E[cur][j].first;
            vis[v] = 1;
            onCircle[v] = ++C;
            cid[C] = v;
            dis[v] = dis[cur] + E[cur][j].second;
            cur = v;
            break;
          }
        if (!flag) break;
      } while (1);
      clen = dis[cid[C]];
      for (int j = (0); j < (E[i].size()); ++j)
        if (E[i][j].first == cid[C]) clen += E[i][j].second;
      break;
    }
  for (int i = (1); i <= (C); ++i) dfs(cid[i], 0);
  long long cur = -INF;
  for (int i = (1); i <= (C); ++i) {
    if (cur > -INF) pre[i] = max(pre[i - 1], cur + dis[cid[i]] + d[cid[i]]);
    cur = max(cur, d[cid[i]] - dis[cid[i]]);
  }
  cur = -INF;
  for (int i = (C); i >= (1); --i) {
    if (cur > -INF) suc[i] = max(suc[i + 1], cur + d[cid[i]] - dis[cid[i]]);
    cur = max(cur, d[cid[i]] + dis[cid[i]]);
  }
  tpre[0] = -INF;
  for (int i = (1); i <= (C); ++i)
    tpre[i] = max(tpre[i - 1], d[cid[i]] + dis[cid[i]]);
  tsuc[C + 1] = -INF;
  for (int i = (C); i >= (1); --i)
    tsuc[i] = max(tsuc[i + 1], d[cid[i]] - dis[cid[i]]);
  for (int i = (1); i <= (C - 1); ++i) {
    long long t = dia;
    t = max(t, pre[i]);
    t = max(t, suc[i + 1]);
    t = max(t, tpre[i] + tsuc[i + 1] + clen);
    best = min(best, t);
  }
  best = min(best, max(dia, pre[C]));
  printf("%lld\n", best);
  return 0;
}
