#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<pair<int, int> > G[N];
vector<int> p, cycle;
bool vis[N];
long long dep[N], L[N];
int k;
long long pre1[N], pre2[N], suf1[N], suf2[N];
void solve(int u) {
  for (int i = 0; i < p.size(); ++i)
    if (p[i] == u) {
      for (int j = i; j < p.size(); ++j) cycle.push_back(p[j]);
      break;
    }
  k = cycle.size();
  for (int i = 0; i < cycle.size(); ++i) {
    int u = cycle[i];
    int aim = cycle[(i + 1) % k];
    for (int j = 0; j < G[u].size(); ++j) {
      pair<int, int> t = G[u][j];
      int v = t.first, w = t.second;
      if (v == aim) {
        L[i] = w;
        break;
      }
    }
  }
}
void findcycle(int u, int fa) {
  vis[u] = 1;
  p.push_back(u);
  bool flag = 1;
  for (int i = 0; i < G[u].size(); ++i) {
    pair<int, int> t = G[u][i];
    int v = t.first, w = t.second;
    if (v == fa && flag) {
      flag = 0;
      continue;
    }
    if (vis[v]) {
      solve(v);
      return;
    }
    findcycle(v, u);
  }
  p.pop_back();
}
long long ans;
long long dfs(int u, int fa) {
  long long first = 0, second = 0;
  dep[u] = 0;
  for (int i = 0; i < G[u].size(); ++i) {
    pair<int, int> t = G[u][i];
    int v = t.first, w = t.second;
    if (v == fa || vis[v]) continue;
    long long dist = w + dfs(v, u);
    if (dist > first)
      second = first, first = dist;
    else if (dist > second)
      second = dist;
    dep[u] = max(dep[u], w + dep[v]);
  }
  ans = max(ans, first + second);
  return first;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    G[u].push_back(make_pair(v, w));
    G[v].push_back(make_pair(u, w));
  }
  findcycle(1, 0);
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < k; ++i) vis[cycle[i]] = 1;
  ans = 0;
  for (int i = 0; i < k; ++i) dfs(cycle[i], 0);
  long long tmp1 = L[0], tmp2 = L[0] + dep[cycle[0]];
  pre1[0] = dep[cycle[0]];
  pre2[0] = 0;
  for (int i = 1; i < k; ++i) {
    pre1[i] = max(pre1[i - 1], tmp1 + dep[cycle[i]]);
    pre2[i] = max(pre2[i - 1], tmp2 + dep[cycle[i]]);
    tmp1 += L[i];
    tmp2 = max(tmp2, dep[cycle[i]]) + L[i];
  }
  suf1[k - 1] = dep[cycle[k - 1]] + L[k - 1];
  suf2[k - 1] = dep[cycle[0]] + L[k - 1] + dep[cycle[k - 1]];
  tmp1 = L[k - 1];
  tmp2 = max(L[k - 1] + dep[cycle[0]], dep[cycle[k - 1]]);
  for (int i = k - 2; i > 0; --i) {
    tmp1 += L[i];
    tmp2 += L[i];
    suf1[i] = max(suf1[i + 1], tmp1 + dep[cycle[i]]);
    suf2[i] = max(suf2[i + 1], tmp2 + dep[cycle[i]]);
    tmp2 = max(tmp2, dep[cycle[i]]);
  }
  long long tmp = 1e18;
  for (int i = 0; i < k; ++i) {
    tmp = min(tmp, max(max(pre2[i], suf2[i + 1]), pre1[i] + suf1[i + 1]));
  }
  ans = max(ans, tmp);
  printf("%I64d\n", ans);
  return 0;
}
