#include <bits/stdc++.h>
namespace IO {
template <typename _T>
inline bool read(_T& x) {
  x = 0;
  _T y = 1;
  char c = getchar();
  while ((c < '0' || '9' < c) && c != EOF) {
    if (c == '-') y = -1;
    c = getchar();
  }
  if (c == EOF) return false;
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
  x *= y;
  return true;
}
template <typename _T>
inline _T input() {
  _T x = 0, y = 1;
  char c = getchar();
  while ((c < '0' || '9' < c) && c != EOF) {
    if (c == '-') y = -1;
    c = getchar();
  }
  if (c == EOF) return 0;
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
  x *= y;
  return x;
}
};  // namespace IO
using namespace IO;
int N, M, top;
int head[300007], to[300007 << 1], nxt[300007 << 1], cap;
int cir[300007], stk[300007];
long long dis[300007 << 1], dn[300007], mx[300007][2], own[300007];
long long sum[300007][2], val[300007][2], res;
bool vis[300007];
inline void addEdge(int u, int v, long long w) {
  nxt[++cap] = head[u];
  head[u] = cap;
  to[cap] = v;
  dis[cap] = w;
}
bool dfs1(int x, int las) {
  if (vis[x]) {
    while (1) {
      cir[++M] = stk[top];
      if (stk[top--] == x) break;
    }
    return false;
  }
  vis[x] = true;
  stk[++top] = x;
  for (int i = head[x]; i; i = nxt[i])
    if (to[i] != las)
      if (!dfs1(to[i], x)) return false;
  top--;
  return true;
}
void dfs2(int x, int now) {
  vis[x] = true;
  for (int i = head[x]; i; i = nxt[i])
    if (cir[now + 1] == to[i]) {
      dn[now] = dis[i];
      if (!vis[to[i]]) dfs2(to[i], now + 1);
    }
}
long long dfs3(int x, int las) {
  long long ans = 0;
  mx[x][0] = mx[x][1] = 0;
  for (int i = head[x]; i; i = nxt[i])
    if (!vis[to[i]] && to[i] != las) {
      ans = std::max(ans, dfs3(to[i], x));
      if (mx[to[i]][0] + dis[i] > mx[x][0])
        mx[x][1] = mx[x][0], mx[x][0] = mx[to[i]][0] + dis[i];
      else if (mx[to[i]][0] + dis[i] > mx[x][1])
        mx[x][1] = mx[to[i]][0] + dis[i];
    }
  ans = std::max(ans, mx[x][0] + mx[x][1]);
  return ans;
}
int main() {
  read(N);
  int u, v, w;
  for (int i = 1; i <= N; ++i) {
    read(u), read(v), read(w);
    addEdge(u, v, w);
    addEdge(v, u, w);
  }
  dfs1(1, 0);
  cir[M + 1] = cir[1];
  for (int i = 1; i <= N; ++i) vis[i] = false;
  dfs2(cir[1], 1);
  for (int i = 1; i <= M; ++i) own[i] = dfs3(cir[i], 0);
  long long tmp = 0;
  int x;
  for (int i = 1; i <= M; ++i) {
    x = cir[i];
    sum[i][0] = std::max(sum[i - 1][0], tmp + mx[x][0]);
    tmp += dn[i];
  }
  tmp = 0;
  for (int i = M; i > 1; --i) {
    x = cir[i];
    sum[i][1] = std::max(sum[i + 1][1], tmp + mx[x][0]);
    tmp += dn[i - 1];
  }
  tmp = 0;
  for (int i = 1; i <= M; ++i) {
    x = cir[i];
    val[i][0] = std::max(val[i - 1][0], std::max(own[i], tmp + mx[x][0]));
    tmp = std::max(tmp, mx[x][0]);
    tmp += dn[i];
  }
  tmp = 0;
  for (int i = M; i > 1; --i) {
    x = cir[i];
    val[i][1] = std::max(val[i + 1][1], std::max(own[i], tmp + mx[x][0]));
    tmp = std::max(tmp, mx[x][0]);
    tmp += dn[i - 1];
  }
  res = val[M][0];
  for (int i = 1; i < M; ++i)
    res = std::min(res, std::max(std::max(val[i][0], val[i + 1][1]),
                                 sum[i][0] + dn[M] + sum[i + 1][1]));
  printf("%I64d\n", res);
  return 0;
}
