#include using namespace std; typedef long long ll; const ll LINF = 4321001001001001001; struct graph { struct edge { int to; ll cost; }; vector> g; vector dist; int n; graph(int n_) : g(n_), dist(n_, LINF), n(n_) {} void addEdge(int from, int to, ll cost) { g[from].push_back(edge{to, cost}); } void addEdgeBoth(int n1, int n2, ll cost) { addEdge(n1, n2, cost); addEdge(n2, n1, cost); } void dijkstra(int st) { for (int i = 0; i < n; i++) dist[i] = LINF; // priority_queue qv // first: distance from st // second: this node using qv = pair; priority_queue, greater> q; dist[st] = 0; q.push(qv{dist[st], st}); while (!q.empty()) { qv now = q.top(); q.pop(); if (now.first > dist[now.second]) continue; for (edge ne : g[now.second]) { ll nd = dist[now.second] + ne.cost; if (dist[ne.to] > nd) { dist[ne.to] = nd; q.push(qv{dist[ne.to], ne.to}); } } } return; } }; int main() { int n; cin >> n; graph g(n); for (int i = 0; i < n - 1; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; g.addEdgeBoth(u, v, w); } ll ans = 0; auto f = [&](auto self, int i, int prev = -1) -> ll { vector vs; for (auto [j, c] : g.g[i]) { if (j == prev) continue; vs.push_back(self(self, j, i) + c); } vs.push_back(0); sort(vs.rbegin(), vs.rend()); if (vs.size() == 1) { ans = max(ans, vs[0]); } else { ans = max(ans, vs[0] + vs[1]); } return vs[0]; }; f(f, 0); cout << ans << endl; return 0; }