#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, k, s, t, a[N], h[N], tot;
int dfn[N], low[N], sta[N], top, dfs_num;
vector<pair<int, int>> e[N];
long long f[N], f1[N], f2[N], g1[N], g2[N], xx, sum[N], w[N];
void tarjan(int u, int fa) {
  dfn[u] = low[u] = ++dfs_num;
  sta[++top] = u;
  int temp = 0;
  for (auto &i : e[u]) {
    int v = i.first;
    if (v == fa && !temp) {
      ++temp;
      continue;
    }
    if (!dfn[v]) {
      tarjan(v, u);
      low[u] = min(low[u], low[v]);
    } else
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    if (sta[top] != u) {
      while (sta[top + 1] != u) {
        a[++tot] = sta[top];
        h[sta[top--]] = 1;
      }
    } else
      top--;
  }
}
int dis(int u, int v, int p = 1) {
  for (auto &i : e[u]) {
    if (i.first == v) {
      if (p == 1)
        return i.second;
      else
        --p;
    }
  }
}
void dfs(int u, int fa) {
  long long x = 0;
  for (auto &i : e[u]) {
    int v = i.first, w = i.second;
    if (v == fa || h[v]) continue;
    dfs(v, u);
    if (f[u] < f[v] + w)
      x = f[u], f[u] = f[v] + w;
    else if (x < f[v] + w)
      x = f[v] + w;
    xx = max(xx, x + f[u]);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s >> t >> k;
    e[s].push_back({t, k});
    e[t].push_back({s, k});
  }
  tarjan(1, 0);
  for (int i = 1; i <= tot; ++i) dfs(a[i], 0);
  for (int i = 2; i <= tot; ++i) sum[i] = sum[i - 1] + dis(a[i], a[i - 1]);
  long long disn1 = dis(a[tot], a[1], tot == 2 ? 2 : 1);
  for (int i = 1; i <= tot; ++i) w[i] = f[a[i]];
  long long mx = 0;
  for (int i = 1; i <= tot; ++i) {
    f1[i] = max(f1[i - 1], w[i] + sum[i] + mx);
    mx = max(mx, w[i] - sum[i]);
    g1[i] = max(g1[i - 1], sum[i] + w[i]);
  }
  mx = 0;
  for (int i = tot; i >= 1; --i) {
    f2[i] = max(f2[i + 1], w[i] - sum[i] + mx);
    mx = max(mx, w[i] + sum[i]);
    g2[i] = max(g2[i + 1], w[i] + sum[tot] - sum[i]);
  }
  long long anss = f1[tot];
  for (int i = 1; i < tot; ++i) {
    long long ans = max(max(f1[i], f2[i + 1]), g1[i] + g2[i + 1] + disn1);
    anss = min(anss, ans);
  }
  cout << max(anss, xx);
}
