#include using namespace std; template struct Edge { int to; T cost; }; using Graph = vector>>; template pair dfs(const Graph &G, int u, int par) { pair ret = make_pair((T)0, u); for (auto e : G[u]) { if (e.to == par) continue; auto next = dfs(G, e.to, u); next.first += e.cost; ret = max(ret, next); } return ret; } template T tree_diamiter(const Graph &G) { pair p = dfs(G, 0, -1); pair q = dfs(G, p.second, -1); return q.first; } int main() { int n; std::cin >> n; Graph G(n); for(int i : std::views::iota(0, n - 1)) { int u, v, w; std::cin >> u >> v >> w; --u, --v; G[u].emplace_back(v, w); G[v].emplace_back(u, w); } std::cout << tree_diamiter(G) << "\n"; }