結果
問題 |
No.3113 The farthest point
|
ユーザー |
|
提出日時 | 2025-04-19 00:48:40 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 789 bytes |
コンパイル時間 | 5,113 ms |
コンパイル使用メモリ | 349,600 KB |
実行使用メモリ | 15,268 KB |
最終ジャッジ日時 | 2025-04-19 00:48:50 |
合計ジャッジ時間 | 9,826 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 WA * 13 |
ソースコード
#include <bits/extc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<ll, int>; struct Edge { int to, co; Edge() {} Edge(int to, int co): to(to), co(co) {} }; int main() { int n; cin >> n; vector<vector<Edge>> g(n); rep(i, n-1) { int a, b, c; cin >> a >> b >> c; --a; --b; g[a].emplace_back(b, c); g[b].emplace_back(a, c); } auto dfs = [&](auto f, int v, ll d=0, int p=-1) -> P { P res(d, v); for (auto [u, w] : g[v]) if (u != p) { res = max(res, f(f, u, d+w, v)); } return res; }; int a = dfs(dfs, 0).second; ll ans = dfs(dfs, a).first; cout << ans << '\n'; return 0; }