#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
vector<pair<int, int>> g[N];
vector<pair<pair<int, int>, int>> circle;
int vis[N], pre[N], prel[N], dep[N];
long long dp[N], mxx = 0;
void dfs1(int u, int fa, int d) {
  vis[u] = true;
  dep[u] = d;
  for (auto e : g[u]) {
    int v = e.first, w = e.second;
    if (v != fa) {
      if (vis[v]) {
        if (dep[v] < dep[u]) {
          circle.push_back({{v, u}, w});
          for (int now = u; now != v; now = pre[now]) {
            circle.push_back({{now, pre[now]}, prel[now]});
          }
        }
      } else {
        pre[v] = u, prel[v] = w;
        dfs1(v, u, d + 1);
      }
    }
  }
}
void dfs2(int u) {
  long long mx = 0;
  for (auto e : g[u]) {
    int v = e.first, w = e.second;
    if (!vis[v]) {
      vis[v] = true;
      dfs2(v);
      dp[u] = max(dp[u], dp[v] + w);
      mxx = max(mxx, mx + dp[v] + w);
      mx = max(mx, dp[v] + w);
    }
  }
}
int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  dfs1(1, -1, 0);
  memset(vis, 0, sizeof(vis));
  for (auto x : circle) {
    vis[x.first.first] = true;
  }
  for (auto x : circle) {
    dfs2(x.first.first);
  }
  long long mx = 0, md = 0;
  vector<long long> a(circle.size() + 1), b(circle.size() + 1);
  for (int i = 0; i < (int)circle.size(); i++) {
    a[i + 1] = max(a[i], dp[circle[i].first.first] + mx);
    b[i + 1] = max(b[i], dp[circle[i].first.first] + md);
    mx = max(mx, dp[circle[i].first.first]) + circle[i].second;
    md += circle[i].second;
  }
  mx = dp[circle[0].first.first];
  md = 0;
  long long px = 0, py = 0;
  long long ans = 1e18;
  for (int i = (int)circle.size() - 1; i >= 0; i--) {
    ans = min(ans, max(a[i + 1], max(px, b[i + 1] + py)));
    md += circle[i].second;
    mx += circle[i].second;
    px = max(px, dp[circle[i].first.first] + mx);
    py = max(py, dp[circle[i].first.first] + md);
    mx = max(mx, dp[circle[i].first.first]);
  }
  cout << max(ans, mxx) << endl;
  return 0;
}
