#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667772160")
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
vector<pair<int, int> > graph[200000 + 7], cycle;
int starting, ending, cost[200000 + 7], mx_node, visit[200000 + 7], vv = 1;
bool flag[200000 + 7];
long long level[200000 + 7], chain_cost[200000 + 7][5];
int dfs(int u, int p) {
  static int cycle_start = -1;
  int v, ret = 0, temp;
  visit[u] = 1;
  for (int i = 0; i < graph[u].size(); i++) {
    v = graph[u][i].first;
    if (v == p) continue;
    if (visit[v] == 1) {
      if (cycle_start == u) continue;
      cycle_start = v;
      starting = v;
      ending = u;
      ret = -1;
      cycle.push_back(make_pair(u, graph[u][i].second));
    } else {
      temp = dfs(v, u);
      if (temp == -1) cycle.push_back(make_pair(u, graph[u][i].second));
      ret = min(ret, temp);
      if (temp == -1 && cycle_start == u) ret = 0;
    }
  }
  return ret;
}
void bfs(int src) {
  level[src] = 0, mx_node = src;
  queue<pair<int, long long> > qu;
  vv++;
  int u, v;
  long long cst;
  qu.push(make_pair(src, 0));
  visit[src] = vv;
  while (!qu.empty()) {
    u = qu.front().first;
    cst = qu.front().second;
    if (cst > level[src]) {
      level[src] = cst;
      mx_node = u;
    }
    qu.pop();
    for (int i = 0; i < graph[u].size(); i++) {
      v = graph[u][i].first;
      if (visit[v] == vv || flag[graph[u][i].second]) continue;
      visit[v] = vv;
      qu.push(make_pair(v, cst + cost[graph[u][i].second]));
    }
  }
}
long long bfs2(int src) {
  queue<pair<int, long long> > qu;
  vv++;
  int u, v;
  long long cst, mx_cst = 0;
  qu.push(make_pair(src, 0));
  visit[src] = vv;
  while (!qu.empty()) {
    u = qu.front().first;
    cst = qu.front().second;
    mx_cst = max(cst, mx_cst);
    qu.pop();
    for (int i = 0; i < graph[u].size(); i++) {
      v = graph[u][i].first;
      if (visit[v] == vv || flag[graph[u][i].second]) continue;
      visit[v] = vv;
      qu.push(make_pair(v, cst + cost[graph[u][i].second]));
    }
  }
  return mx_cst;
}
int main() {
  int n, u, v, w;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &u, &v, &w);
    graph[u].push_back(make_pair(v, i));
    graph[v].push_back(make_pair(u, i));
    cost[i] = w;
  }
  dfs(1, -1);
  reverse(cycle.begin(), cycle.end());
  for (int i = 0; i < cycle.size(); i++) flag[cycle[i].second] = 1;
  long long mx_cst = 0, tcost = 0, mx = 0, i_d = 0;
  for (int i = 0; i < cycle.size(); i++) {
    bfs(cycle[i].first);
    mx_cst = max(mx_cst, bfs2(mx_node));
    if (i > 0) chain_cost[i][2] = chain_cost[i - 1][2];
    chain_cost[i][2] = max(i_d + level[cycle[i].first], chain_cost[i][2]);
    i_d = max(i_d, level[cycle[i].first]);
    chain_cost[i][0] = max(mx, tcost + level[cycle[i].first]);
    tcost += cost[cycle[i].second];
    mx = max(mx, chain_cost[i][0]);
    i_d += cost[cycle[i].second];
  }
  tcost = 0;
  mx = 0;
  i_d = 0;
  for (int i = cycle.size() - 1; i >= 0; i--) {
    if (i + 1 < cycle.size())
      tcost += cost[cycle[i].second], i_d += cost[cycle[i].second],
          chain_cost[i][3] = chain_cost[i + 1][3];
    chain_cost[i][3] = max(i_d + level[cycle[i].first], chain_cost[i][3]);
    i_d = max(i_d, level[cycle[i].first]);
    chain_cost[i][1] = max(mx, tcost + level[cycle[i].first]);
    mx = max(mx, chain_cost[i][1]);
  }
  long long mn_cost =
      max(chain_cost[cycle.size() - 1][0], chain_cost[cycle.size() - 1][2]);
  for (int i = 0; i + 1 < cycle.size(); i++)
    mn_cost = min(mn_cost, max(chain_cost[i][0] + chain_cost[i + 1][1] +
                                   cost[cycle.back().second],
                               max(chain_cost[i][2], chain_cost[i + 1][3])));
  mn_cost = max(mn_cost, mx_cst);
  printf("%lld\n", mn_cost);
  return 0;
}
