#include <bits/stdc++.h>
using namespace std;
int n, bb[200005], way[10005][10005], res, ans = 1e9, visited[10005][10005], val[200005];
vector<int> adj[200005];
void kahn() {
queue<int> q;
for (int i = 1; i <= n; i++)
if (bb[i] == 1)
q.push(i);
int u;
while (!q.empty()) {
u = q.front();
q.pop();
for (int v : adj[u]) {
if (bb[v] > 1)
val[v] = max(val[v], val[u] + way[u][v]);
bb[v]--;
bb[u]--;
if (bb[v] == 1)
q.push(v), visited[u][v] = visited[v][u] = 1;
}
}
for (int v : adj[u])
res = res + val[v] + way[v][u];
for (int v : adj[u])
ans = min(ans, max(res - (way[v][u]+val[v]), val[v]));
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
freopen("diameter.inp", "r", stdin);
freopen("diameter.out", "w", stdout);
cin >> n;
for (int i = 1; i < n; i++) {
int x, y, z;
cin >> x >> y >> z;
adj[x].push_back(y);
adj[y].push_back(x);
bb[x]++;
bb[y]++;
way[x][y] = way[y][x] = z;
}
kahn();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBuLCBiYlsyMDAwMDVdLCB3YXlbMTAwMDVdWzEwMDA1XSwgcmVzLCBhbnMgPSAxZTksIHZpc2l0ZWRbMTAwMDVdWzEwMDA1XSwgdmFsWzIwMDAwNV07CnZlY3RvcjxpbnQ+IGFkalsyMDAwMDVdOwoKdm9pZCBrYWhuKCkgewogIHF1ZXVlPGludD4gcTsKICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspCiAgICBpZiAoYmJbaV0gPT0gMSkKICAgICAgcS5wdXNoKGkpOwogIGludCB1OwogIHdoaWxlICghcS5lbXB0eSgpKSB7CiAgICB1ID0gcS5mcm9udCgpOwogICAgcS5wb3AoKTsKICAgIGZvciAoaW50IHYgOiBhZGpbdV0pIHsKICAgICAgaWYgKGJiW3ZdID4gMSkKICAgICAgICB2YWxbdl0gPSBtYXgodmFsW3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