#include <bits/stdc++.h>
using namespace std;
class Edge {
 public:
  int u, v, w;
  Edge(int u, int v, int w) {
    this->u = u;
    this->v = v;
    this->w = w;
  }
};
vector<Edge> tnode;
vector<pair<int, int> > node[(int)2e6];
int color[(int)2e6];
int stParent[(int)2e6];
int star = 0;
long long dp[(int)2e6];
int Field[(int)2e6];
long long l[(int)2e6], r[(int)2e6], lm[(int)2e6], rm[(int)2e6], tmp;
int dfs(int u, int from, int w) {
  if (color[u]) {
    star = u;
    return -1;
  }
  color[u]++;
  for (int i = 0; i < (int)node[u].size(); i++) {
    int v = node[u][i].first, w = node[u][i].second;
    if (v != from) {
      int res = dfs(v, u, w);
      if (res == -1) {
        tnode.push_back(Edge(v, u, w));
        if (u == star) return 0;
        return -1;
      }
    }
  }
  return 0;
}
long long tMax = 0;
void magic(int u, int from) {
  for (int i = 0; i < (int)node[u].size(); i++) {
    int v = node[u][i].first;
    long long w = node[u][i].second;
    if (!Field[v] and v != from) {
      magic(v, u);
      tMax = max(tMax, dp[u] + dp[v] + w);
      dp[u] = max(dp[u], dp[v] + w);
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    node[a].push_back(make_pair(b, c));
    node[b].push_back(make_pair(a, c));
  }
  dfs(1, -1, -1);
  int k = tnode.size();
  for (int i = 0; i < k; i++) {
    Edge one = tnode[i];
    Field[one.u]++;
  }
  for (int i = 0; i < k; i++) {
    Edge one = tnode[i];
    magic(one.u, one.v);
  }
  for (int i = 0, j = 1; i < k; i++, j++) {
    lm[j] = max(dp[tnode[i].u] + tmp, lm[j - 1]);
    tmp = max(tmp, dp[tnode[i].u]) + tnode[i].w;
  }
  tmp = 0;
  vector<Edge> need = tnode;
  need.push_back(tnode[0]);
  reverse(need.begin(), need.end());
  for (int i = 0; i < (int)need.size() - 1; i++) need[i].w = need[i + 1].w;
  need.pop_back();
  for (int i = 0, j = 1; i < k; i++, j++) {
    rm[j] = max(dp[need[i].u] + tmp, rm[j - 1]);
    tmp = max(tmp, dp[need[i].u]) + need[i].w;
  }
  long long rem = dp[star];
  dp[star] = 0;
  long long ans = 1e18;
  tmp = 0;
  for (int i = 0, j = 1; i < k; i++, j++) {
    l[j] = max(l[j - 1], dp[tnode[i].u] + tmp);
    tmp += tnode[i].w;
  }
  tmp = 0;
  for (int i = 0, j = 1; i < k; i++, j++) {
    r[j] = max(r[j - 1], dp[need[i].u] + tmp);
    tmp += need[i].w;
  }
  for (int i = 0; i < k; i++) {
    ans =
        min(ans, max(rm[k - i],
                     max(lm[i + 1], max(l[i + 1] + r[k - i],
                                        max(l[i + 1] + rem, r[k - i] + rem)))));
  }
  cout << max(ans, tMax);
  return 0;
}
