#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, dis;
} temp;
vector<Edge> vec[200005];
int deg[200005];
long long maxx[200005][2];
bool life[200005];
int cnt = 0;
int no[200005];
long long diss[200005], gg, ans = 0;
long long l[3][200005], r[3][200005];
queue<int> q;
void dfs(int x, int fa, long long now) {
  if (deg[x] == 1) {
    gg = now;
    return;
  }
  ans = max(ans, maxx[x][0] + maxx[x][1]);
  deg[x]--;
  diss[cnt] = now;
  no[cnt] = x;
  cnt++;
  for (int i = 0; i < vec[x].size(); i++) {
    if (!life[vec[x][i].to] && vec[x][i].to != fa) {
      dfs(vec[x][i].to, x, now + vec[x][i].dis);
      return;
    }
  }
}
int main() {
  int n, u, v;
  long long wtf, qs;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%lld", &u, &v, &temp.dis);
    temp.to = v;
    vec[u].push_back(temp);
    temp.to = u;
    vec[v].push_back(temp);
    deg[u]++;
    deg[v]++;
  }
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 1) {
      life[i] = 1;
      q.push(i);
    }
  }
  while (!q.empty()) {
    u = q.front();
    q.pop();
    ans = max(ans, maxx[u][0] + maxx[u][1]);
    for (int i = 0; i < vec[u].size(); i++) {
      if (!life[vec[u][i].to]) {
        if (maxx[u][0] + vec[u][i].dis > maxx[vec[u][i].to][0]) {
          maxx[vec[u][i].to][1] = maxx[vec[u][i].to][0];
          maxx[vec[u][i].to][0] = maxx[u][0] + vec[u][i].dis;
        } else
          maxx[vec[u][i].to][1] =
              max(maxx[vec[u][i].to][1], maxx[u][0] + vec[u][i].dis);
        deg[vec[u][i].to]--;
        if (deg[vec[u][i].to] == 1) {
          q.push(vec[u][i].to);
          life[vec[u][i].to] = 1;
        }
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!life[i]) {
      dfs(i, 0, 0);
      l[0][0] = l[1][0] = maxx[no[0]][0];
      l[2][0] = 0;
      for (int j = 1; j < cnt; j++) {
        l[0][j] = max(maxx[no[j]][0] + diss[j], l[0][j - 1]);
        l[1][j] = max(maxx[no[j]][0] - diss[j], l[1][j - 1]);
        l[2][j] = max(l[2][j - 1], maxx[no[j]][0] + diss[j] + l[1][j - 1]);
      }
      r[0][cnt - 1] = maxx[no[cnt - 1]][0] + (gg - diss[cnt - 1]);
      r[1][cnt - 1] = maxx[no[cnt - 1]][0] - (gg - diss[cnt - 1]);
      r[2][cnt - 1] = 0;
      for (int j = cnt - 2; j >= 0; j--) {
        r[0][j] = max(maxx[no[j]][0] + (gg - diss[j]), r[0][j + 1]);
        r[1][j] = max(maxx[no[j]][0] - (gg - diss[j]), r[1][j + 1]);
        r[2][j] =
            max(r[2][j + 1], maxx[no[j]][0] + (gg - diss[j]) + r[1][j + 1]);
      }
      wtf = l[2][cnt - 1];
      for (int j = 1; j < cnt; j++) {
        qs = 0;
        qs = max(qs, l[0][j - 1] + r[0][j]);
        if (j >= 2) qs = max(qs, l[2][j - 1]);
        if (j < cnt - 1) qs = max(qs, r[2][j]);
        wtf = min(wtf, qs);
      }
      printf("%lld\n", max(wtf, ans));
      break;
    }
  }
  return 0;
}
