#include using namespace std; const int MAX_N = 200000; vector> adj[MAX_N]; pair dfs(int v, int parent) { pair res = {v, 0}; for (auto& edge : adj[v]) { int u = edge.first; long long w = edge.second; if (u != parent) { auto next = dfs(u, v); next.second += w; if (next.second > res.second) { res = next; } } } return res; } int main() { int N; cin >> N; for (int i = 0; i < N - 1; ++i) { int u, v, w; cin >> u >> v >> w; u--; v--; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } pair first = dfs(0, -1); pair second = dfs(first.first, -1); cout << second.second << endl; return 0; }