#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 7;
const int M = 20;
const int inf = 1e9 + 7;
const long long linf = 1e18 + 7;
const double pi = acos(-1);
const double eps = 1e-7;
const bool multipleTest = false;
long long maxLength[N];
long long maxPath[N];
bool check[N];
vector<pair<int, int> > adj[N];
pair<pair<int, int>, int> edge[N];
int n;
void dfs(int u, int r) {
  maxLength[u] = maxPath[u] = -linf;
  for (pair<int, int>& x : adj[u]) {
    int v = x.first;
    int c = edge[x.second].second;
    if (v != r && !check[v]) {
      dfs(v, u);
      maxPath[u] =
          max(maxPath[u], max(maxPath[v], maxLength[u] + maxLength[v] + c));
      maxLength[u] = max(maxLength[u], maxLength[v] + c);
    }
  }
  maxLength[u] = max(maxLength[u], 0ll);
  maxPath[u] = max(maxPath[u], maxLength[u]);
}
int pa[N];
int diff = 0;
void findDiff(int u, int r) {
  pa[u] = r;
  for (pair<int, int>& x : adj[u]) {
    int v = x.first;
    if (v != r) {
      if (pa[v] == 0) {
        findDiff(v, u);
      } else {
        diff = x.second;
      }
    }
  }
}
pair<int, int> trace[N];
void go(int u) {
  for (pair<int, int>& x : adj[u]) {
    if (!trace[x.first].first && x.second != diff) {
      trace[x.first] = make_pair(u, x.second);
      go(x.first);
    }
  }
}
int r[N];
int len[N];
int k = 0;
long long dpLeft[N];
long long dpRight[N];
long long LL[N];
long long RR[N];
void solve() {
  cin >> n;
  edge[0] = make_pair(make_pair(0, 0), 0);
  for (int i = 1; i <= n; ++i) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    edge[i] = make_pair(make_pair(u, v), c);
    adj[u].push_back(make_pair(v, i));
    adj[v].push_back(make_pair(u, i));
  }
  findDiff(1, -1);
  trace[edge[diff].first.first] = make_pair(-1, 0);
  go(edge[diff].first.first);
  int u = edge[diff].first.second;
  while (u != -1) {
    r[++k] = u;
    check[u] = 1;
    len[k] = edge[trace[u].second].second;
    u = trace[u].first;
  }
  for (int i = 1; i <= k; ++i) dfs(r[i], -1);
  LL[0] = -linf;
  RR[k + 1] = -linf;
  long long ans = linf;
  long long mxLength = -linf;
  long long curSum = 0;
  for (int i = 1; i <= k; ++i) {
    dpLeft[i] =
        max(dpLeft[i - 1],
            max(maxPath[r[i]], maxLength[r[i]] + mxLength + len[i - 1]));
    mxLength = max(mxLength + len[i - 1], maxLength[r[i]]);
    curSum += len[i - 1];
    LL[i] = max(LL[i - 1], curSum + maxLength[r[i]]);
  }
  ans = dpLeft[k];
  mxLength = -linf;
  curSum = 0;
  for (int i = k; i > 1; --i) {
    dpRight[i] = max(dpRight[i + 1],
                     max(maxPath[r[i]], maxLength[r[i]] + mxLength + len[i]));
    mxLength = max(mxLength + len[i], maxLength[r[i]]);
    curSum += len[i];
    RR[i] = max(RR[i + 1], maxLength[r[i]] + curSum);
    ans = min(ans, max(max(dpRight[i], dpLeft[i - 1]),
                       LL[i - 1] + RR[i] + edge[diff].second));
  }
  cout << ans << '\n';
}
int main() {
  int Test = 1;
  if (multipleTest) {
    cin >> Test;
  }
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}
