#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long expo(long long base, long long pow) {
  long long ans = 1;
  while (pow != 0) {
    if (pow & 1 == 1) {
      ans = ans * base;
      ans = ans % mod;
    }
    base *= base;
    base %= mod;
    pow /= 2;
  }
  return ans;
}
long long inv(long long x) { return expo(x, mod - 2); }
double pi = 3.141592653589793238462643;
double error = 0.0000001;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int M = 300001;
int n, a[M], b[M], parent[M], st = 0, en = 0;
int vis[M], cycle[M], cyclic[M], conn, leading_edge[M];
long long depth[M], diameter, pref_d[M], suf_d[M], pref_far[M], suff_far[M],
    c[M];
vector<int> vec[M];
void dfs(int u, int p) {
  vis[u] = 1;
  for (int ind = 0; ind < vec[u].size(); ind++) {
    int edge_num = vec[u][ind];
    int v = a[edge_num] ^ b[edge_num] ^ u;
    if (v != p) {
      if (vis[v]) {
        st = u, en = v, conn = edge_num;
        return;
      }
      parent[v] = edge_num;
      dfs(v, u);
    }
  }
}
long long dfss(int u, int p) {
  long long one = 0, two = 0;
  for (int ind = 0; ind < vec[u].size(); ind++) {
    int edge_num = vec[u][ind];
    int v = a[edge_num] ^ b[edge_num] ^ u;
    if (v == p || cyclic[v]) continue;
    long long max_depth = dfss(v, u) + c[edge_num];
    if (max_depth > one) {
      two = one;
      one = max_depth;
    } else if (max_depth > two) {
      two = max_depth;
    }
  }
  diameter = max(diameter, one + two);
  return one;
}
int main() {
  scanf("%d", &(n));
  diameter = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(a[i]));
    scanf("%d", &(b[i]));
    scanf("%lld", &(c[i]));
    vec[a[i]].push_back(i);
    vec[b[i]].push_back(i);
  }
  dfs(1, 0);
  int put = 1;
  while (en != st) {
    cycle[put] = en;
    int edge_num = parent[en];
    int prev = a[edge_num] ^ b[edge_num] ^ en;
    en = prev;
    leading_edge[put] = edge_num;
    put++;
  }
  cycle[put] = st;
  leading_edge[put] = conn;
  for (int i = 1; i <= put; i++) {
    cyclic[cycle[i]] = 1;
  }
  for (int i = 1; i <= put; i++) {
    depth[i] = dfss(cycle[i], 0);
  }
  pref_d[1] = depth[1];
  long long mx = depth[1];
  long long prefix = c[leading_edge[1]];
  for (int i = 2; i <= put; i++) {
    pref_d[i] = max(pref_d[i - 1], depth[i] + prefix + mx);
    mx = max(mx, depth[i] - prefix);
    prefix += c[leading_edge[i]];
  }
  suf_d[put] = depth[put];
  mx = depth[put];
  long long suffix = 0;
  for (int i = put - 1; i >= 1; i--) {
    suffix += c[leading_edge[i]];
    suf_d[i] = max(suf_d[i + 1], depth[i] + suffix + mx);
    mx = max(mx, depth[i] - suffix);
  }
  prefix = 0;
  suffix = 0;
  for (int i = 1; i <= put; i++) {
    pref_far[i] = max(pref_far[i - 1], prefix + depth[i]);
    prefix += c[leading_edge[i]];
  }
  suff_far[put] = depth[put];
  for (int i = put - 1; i >= 1; i--) {
    suffix += c[leading_edge[i]];
    suff_far[i] = max(suff_far[i + 1], suffix + depth[i]);
  }
  long long ans = max(diameter, pref_d[put]);
  for (int i = 1; i < put; i++) {
    long long temp = diameter;
    temp = max(temp, pref_d[i]);
    temp = max(temp, suf_d[i + 1]);
    temp = max(temp, pref_far[i] + suff_far[i + 1] + c[leading_edge[put]]);
    ans = min(ans, temp);
  }
  cout << ans;
}
