#include <bits/stdc++.h>
using namespace std;
vector<int> cycle;
vector<long long> d, h;
struct data {
  long long mx, neg, pos;
};
struct node {
  node *left, *right;
  int start, end, mid;
  data v;
  void merge(data &v, data &l, data &r) {
    v.mx = max(l.mx, max(r.mx, l.neg + r.pos));
    v.pos = max(l.pos, r.pos);
    v.neg = max(l.neg, r.neg);
  }
  node(int start, int end) : start(start), end(end) {
    if (start != end) {
      mid = (start + end) / 2;
      left = new node(start, mid);
      right = new node(mid + 1, end);
      merge(v, left->v, right->v);
    } else {
      v.pos = h[start] + d[start];
      v.neg = h[start] - d[start];
      v.mx = -1;
    }
  }
  data query(int a, int b) {
    if (a == start && b == end) {
      return v;
    }
    if (b <= mid) return left->query(a, b);
    if (a > mid) return right->query(a, b);
    data l = left->query(a, mid);
    data r = right->query(mid + 1, b);
    data ret;
    merge(ret, l, r);
    return ret;
  }
};
vector<vector<pair<int, long long>>> g;
vector<int> seen, in;
bool go(int u, int p, vector<int> &cycle, vector<long long> &d) {
  seen[u] = 1;
  for (auto &v : g[u]) {
    if (!seen[v.first]) {
      if (go(v.first, u, cycle, d)) {
        cycle.push_back(v.first);
        d.push_back(v.second);
        seen[v.first] = 2;
        return seen[u] != 2;
      }
    } else if (v.first != p && seen[v.first]) {
      seen[v.first] = 2;
      cycle.push_back(v.first);
      d.push_back(v.second);
      return true;
    }
  }
  return false;
}
long long get_h(int u, int p) {
  long long ans = 0;
  for (auto &v : g[u]) {
    if (p != v.first && seen[v.first] != 2) {
      ans = max(ans, get_h(v.first, u) + v.second);
    }
  }
  return ans;
}
pair<int, int> edge;
void dfs(int u, int p, int &f, long long &best, long long d) {
  if (d > best) {
    best = d;
    f = u;
  }
  for (auto &v : g[u]) {
    if ((u == edge.first && v.first == edge.second) ||
        (v.first == edge.first && u == edge.second))
      continue;
    if (v.first != p) dfs(v.first, u, f, best, d + v.second);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a, b;
  long long x;
  g.assign(n + 1, vector<pair<int, long long>>());
  for (int i = 0; i < n; ++i) {
    cin >> a >> b >> x;
    g[a].push_back({b, x});
    g[b].push_back({a, x});
  }
  seen.assign(n + 1, 0);
  go(1, -1, cycle, d);
  cycle.resize(cycle.size() * 2);
  d.resize(d.size() * 2);
  int lim = d.size() / 2;
  for (int i = 0; i < lim; ++i) d[i + lim] = d[i];
  lim = cycle.size() / 2;
  for (int i = 0; i < lim; ++i) cycle[i + lim] = cycle[i];
  d.insert(d.begin(), 0);
  for (int i = 1; i < d.size(); ++i) {
    d[i] += d[i - 1];
  }
  h.resize(2 * lim);
  for (int i = 0; i < lim; ++i) {
    h[i] = h[i + lim] = get_h(cycle[i], -1);
  }
  node tree(0, cycle.size() - 1);
  long long best = LLONG_MAX;
  for (int i = 1; i <= lim; ++i) {
    long long cur = tree.query(i, i + lim - 1).mx;
    if (cur < best) {
      best = cur;
      edge = {cycle[i - 1], cycle[i]};
    }
  }
  int f;
  best = -1;
  dfs(1, -1, f, best, 0);
  best = -1;
  dfs(f, -1, f, best, 0);
  cout << best << '\n';
}
