#include using namespace std; using ll = long long; struct Edge { int to; ll w; }; vector> adj; ll max_dist; int max_v; void dfs(int v, int p, ll d) { if (d > max_dist) max_dist = d, max_v = v; for (auto& e : adj[v]) if (e.to != p) dfs(e.to, v, d + e.w); } int main() { int N; cin >> N; adj.resize(N + 1); for (int i = 0; i < N - 1; ++i) { int u, v; ll w; cin >> u >> v >> w; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } max_dist = -1e18; dfs(1, -1, 0); int start = max_v; max_dist = -1e18; dfs(start, -1, 0); cout << max_dist << endl; return 0; }