#include #include #include #include using namespace std; using ll = long long; const int MAXN = 200005; vector> graph[MAXN]; struct Result { int node; ll dist; }; Result dfs(int node, int parent, ll dist) { Result res = {node, dist}; for (auto [next, weight] : graph[node]) { if (next == parent) continue; Result tmp = dfs(next, node, dist + weight); if (tmp.dist > res.dist) { res = tmp; } } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for (int i = 0; i < n - 1; ++i) { int u, v; ll w; cin >> u >> v >> w; graph[u].emplace_back(v, w); graph[v].emplace_back(u, w); } Result r1 = dfs(1, -1, 0); Result r2 = dfs(r1.node, -1, 0); cout << max(r2.dist, 0LL) << '\n'; return 0; }