#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long inf = 0xc0c0c0c0c0c0c0c0;
const double pi = acos(-1);
const int MAXN = 2e5 + 7;
struct edge {
  int to, nxt, len;
};
edge E[MAXN << 1];
int G[MAXN], ecnt;
int deg[MAXN];
int vis[MAXN];
long long len[MAXN];
long long Max;
int N;
queue<int> q1, q2;
long long p[MAXN], e[MAXN];
long long pre[MAXN], suf[MAXN], dist[MAXN];
long long res[MAXN];
void bfs() {
  q1.push(1);
  vis[1] = 1;
  int i;
  while (!q1.empty()) {
    int u = q1.front();
    q1.pop();
    if (deg[u] == 1) q2.push(u);
    for (i = G[u]; ~i; i = E[i].nxt) {
      int v = E[i].to;
      if (!vis[v]) {
        vis[v] = 1;
        q1.push(v);
      }
    }
  }
}
void topo() {
  int i;
  while (!q2.empty()) {
    int u = q2.front();
    q2.pop();
    for (i = G[u]; ~i; i = E[i].nxt) {
      int v = E[i].to;
      if (deg[v] > 1) {
        Max = max(Max, len[v] + len[u] + E[i].len);
        len[v] = max(len[v], len[u] + E[i].len);
        if (--deg[v] == 1) q2.push(v);
      }
    }
  }
}
void addedge(int from, int to, int weight) {
  E[ecnt] = edge{to, G[from], weight};
  G[from] = ecnt++;
}
void clear(int x) {
  while (x--) pre[x] = suf[x] = 0;
}
void show(long long *arr, int sz, char *ch) {
  for (int i = 0; i < sz; i++) cout << arr[i] << " ";
  puts(ch);
}
void solve(int x) {
  int top = 0;
  p[0] = x;
  dist[0] = len[x];
  int last = -1;
  int y, i;
  for (y = x; 1;) {
    for (i = G[y]; ~i; i = E[i].nxt) {
      if (i != last && deg[y = E[i].to] == 2) break;
    }
    last = i ^ 1;
    e[top++] = E[i].len;
    p[top] = y;
    dist[top] = len[y];
    if (y == x) break;
  }
  clear(top);
  pre[0] = dist[0];
  long long sum = 0;
  for (i = 1; i < top; i++) {
    sum += e[i - 1];
    pre[i] = max(pre[i - 1], dist[i] + sum);
  }
  suf[top] = inf;
  sum = 0;
  for (i = top - 1; ~i; i--) {
    sum += e[i];
    suf[i] = max(suf[i + 1], dist[i] + sum);
  }
  for (i = 0; i < top; i++) res[i] = pre[i] + suf[i + 1];
  clear(top);
  pre[0] = dist[0];
  long long m = 0;
  for (i = 1; i < top; i++) {
    m = max(m, pre[i - 1] + e[i - 1] + dist[i]);
    pre[i] = max(pre[i - 1] + e[i - 1], dist[i]);
    res[i] = max(res[i], m);
  }
  suf[top] = dist[0] + e[top - 1];
  m = 0;
  for (i = top - 1; i; i--) {
    m = max(m, suf[i + 1] + dist[i]);
    res[i - 1] = max(res[i - 1], m);
    suf[i] = max(dist[i], suf[i + 1]) + e[i - 1];
  }
  m = INF;
  for (i = 0; i < top; i++) {
    m = min(m, res[i]);
    res[i] = 0;
  }
  Max = max(Max, m);
}
void init() {
  ecnt = Max = 0;
  for (int i = 0; i <= N; i++) {
    G[i] = -1;
    len[i] = 0;
  }
}
int main() {
  scanf("%d", &N);
  init();
  int i, j, k;
  for (i = 0; i < N; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
    deg[u]++;
    deg[v]++;
  }
  bfs();
  topo();
  for (i = 1; i <= N; i++)
    if (deg[i] == 2) break;
  solve(i);
  printf("%lld\n", Max);
  return 0;
}
