#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const long long infll = (long long)1e18 + 7;
int n, vis[N], cycle_s;
long long preone[N], sufone[N], premx[N], sufmx[N], dep[N], w[N];
vector<int> cycle;
vector<pair<int, int> > g[N];
int dfscyc(int u, int fa) {
  vis[u] = 1;
  for (auto pi : g[u])
    if (pi.first != fa) {
      int v = pi.first;
      if (vis[v] == 1) {
        cycle_s = v;
        cycle.push_back(u);
        return 1;
      } else if (vis[v] == 0) {
        int ret = dfscyc(v, u);
        if (ret == -1) return -1;
        if (ret == 1) {
          cycle.push_back(u);
          if (u == cycle_s)
            return -1;
          else
            return 1;
        }
      }
    }
  vis[u] = 2;
  return 0;
}
pair<long long, int> dfsdep(int u, int fa,
                            pair<int, int> notvis = make_pair(-1, -1)) {
  pair<long long, int> ret = make_pair(0, u);
  vis[u] = true;
  for (auto& e : g[u]) {
    int v = e.first;
    long long c = e.second;
    if (vis[v] || make_pair(u, v) == notvis || make_pair(v, u) == notvis)
      continue;
    auto pi = dfsdep(v, u, notvis);
    pi.first += c;
    ret = max(ret, pi);
  }
  return ret;
}
long long dfstwice(pair<int, int> notvis) {
  int u = notvis.first;
  memset(vis, 0, sizeof(vis));
  auto pi = dfsdep(u, -1, notvis);
  memset(vis, 0, sizeof(vis));
  return dfsdep(pi.second, -1, notvis).first;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v, l; i <= n; ++i) {
    scanf("%d%d%d", &u, &v, &l);
    g[u].push_back({v, l});
    g[v].push_back({u, l});
  }
  dfscyc(1, -1);
  int k = cycle.size();
  memset(vis, 0, sizeof(vis));
  for (int u : cycle) vis[u] = true;
  for (int i = 0; i < k; ++i) dep[i] = dfsdep(cycle[i], -1).first;
  cycle.push_back(cycle[0]);
  for (int i = 0; i < k; ++i) {
    int u = cycle[i], v = cycle[i + 1];
    for (int j = 0; j < g[u].size(); ++j)
      if (g[u][j].first == v) {
        w[i] = g[u][j].second;
        break;
      }
  }
  preone[0] = dep[0];
  premx[0] = dep[0];
  long long toone = 0;
  long long before = -infll;
  for (int i = 1; i < k; ++i) {
    toone = toone + w[i - 1];
    preone[i] = max(preone[i - 1], toone + dep[i]);
    before = max(before, dep[i - 1]) + w[i - 1];
    premx[i] = max(premx[i - 1], before + dep[i]);
  }
  sufone[k] = -infll;
  sufmx[k] = -infll;
  toone = 0;
  before = -infll;
  for (int i = k - 1; i > 0; --i) {
    toone = toone + w[i];
    sufone[i] = max(sufone[i + 1], toone + dep[i]);
    before = max(before, dep[i + 1]) + w[i];
    sufmx[i] = max(sufmx[i + 1], before + dep[i]);
  }
  auto pi = make_pair(infll, 0);
  for (int i = 0; i < k; ++i) {
    long long ret = max(preone[i] + sufone[i + 1], max(premx[i], sufmx[i + 1]));
    if (ret < pi.first) {
      pi = make_pair(ret, i);
    }
  }
  cout << dfstwice(make_pair(cycle[pi.second], cycle[pi.second + 1])) << endl;
  return 0;
}
