#include using namespace std; using ll = long long; const int iinf = 1e9; const ll inf = 1e18; template ostream& operator<<(ostream &o, vector v) { for (int i = 0; i < v.size(); i++) o << v[i] << (i+1sync_with_stdio(false); int n; cin >> n; vector> g(n); for (int i = 0; i < n-1; i++) { int u, v; ll w; cin >> u >> v >> w; u--, v--; g[u].push_back({v, w}); g[v].push_back({u, w}); } auto farthest = [&](int u) -> Edge { vector d(n, inf); d[u] = 0; queue q; q.push(u); while (!q.empty()) { int v = q.front(); q.pop(); for (auto e : g[v]) { if (d[e.to] != inf) continue; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; if (e.to != u) q.push(e.to); } } } int mi = 0; for (int i = 0; i < n; i++) { if (d[i] > d[mi]) mi = i; } return {mi, d[mi]}; }; auto [x, _] = farthest(0); auto [y, ans] = farthest(x); cout << ans << endl; return 0; }