
# include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
vector <pii> v[10005];
int n, ans, a, b, c;
int dfs (int u, int f) {
int maxx = 0, x = 0, y = 0;
for (pii i : v[u]) {
if (i.first == f)
continue ;
maxx = max (maxx, dfs (i.first, u) + i.second);
if (maxx >= x)
y = x, x = maxx;
else if (maxx > y)
y = maxx;
}
ans = max (ans, x + y);
return maxx;
}
int main () {
cin >> n;
while (-- n) {
cin >> a >> b >> c;
v[a].push_back ({b, c});
v[b].push_back ({a, c});
}
dfs (1, -1);
cout << ans;
return 0;
}
10
1 4 46
6 7 30
7 8 17
1 9 4
2 5 24
6 10 17
1 6 16
2 3 15
1 2 23
126
110