結果
問題 |
No.3113 The farthest point
|
ユーザー |
|
提出日時 | 2025-04-19 02:58:48 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 814 bytes |
コンパイル時間 | 3,418 ms |
コンパイル使用メモリ | 278,388 KB |
実行使用メモリ | 18,012 KB |
最終ジャッジ日時 | 2025-04-19 02:58:55 |
合計ジャッジ時間 | 6,860 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#include<bits/stdc++.h> using ll = long long; #define var auto const char newl = '\n'; using namespace std; bool solve(){ return true; } ll res = 0; vector<vector<pair<int, ll>>> g; ll solve(ll node, ll par) { ll mx1 = 0, mx2 = 0; for (var [adj, w] : g[node]) { if (adj == par) continue; var nxt = solve(adj, node) + w; if (mx1 < nxt) { mx2 = mx1; mx1 = nxt; } else if (mx2 < nxt) { mx2 = nxt; } } res = max(res, mx1 + mx2); return mx1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; g = vector<vector<pair<int, ll>>>(n); for (int i = 0; i < n - 1; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; g[u].emplace_back(v, w); g[v].emplace_back(u, w); } solve(0, -1); cout << res << endl; }