#include //#include using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* 木DP dp(i) = 頂点iを末端とする重み最大のパス これと、各頂点iをLCAとするパスが候補。 */ ll N, ans=0; cin >> N; vector>> E(N); for (int i=0; i> u >> v >> c; u--; v--; E[u].push_back({v, c}); E[v].push_back({u, c}); } auto dfs=[&](auto self, int from, int p)->ll{ vector v; ll res=0; for (auto [to, c] : E[from]){ if (to == p) continue; ll x = self(self, to, from); v.push_back(x+c); } sort(v.rbegin(), v.rend()); if (v.size() >= 1){ ans = max(ans, v[0]); res = max(res, v[0]); } if (v.size() >= 2){ ans = max(ans, v[0]+v[1]); } return res; }; dfs(dfs, 0, -1); cout << ans << endl; return 0; }