結果
問題 |
No.3113 The farthest point
|
ユーザー |
|
提出日時 | 2025-04-19 13:55:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 870 bytes |
コンパイル時間 | 644 ms |
コンパイル使用メモリ | 77,428 KB |
実行使用メモリ | 18,392 KB |
最終ジャッジ日時 | 2025-04-19 13:55:40 |
合計ジャッジ時間 | 6,274 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 WA * 13 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; const int MAXN = 200005; using ll = long long; vector<pair<int, ll>> graph[MAXN]; bool visited[MAXN]; struct Result { int node; ll dist; }; Result dfs(int node, int parent, ll dist) { Result res = {node, dist}; for (auto [next, weight] : graph[node]) { if (next == parent) continue; Result tmp = dfs(next, node, dist + weight); if (tmp.dist > res.dist) { res = tmp; } } return res; } int main() { int n; cin >> n; for (int i = 0; i < n - 1; ++i) { int u, v; ll w; cin >> u >> v >> w; graph[u].emplace_back(v, w); graph[v].emplace_back(u, w); } Result r1 = dfs(1, -1, 0); Result r2 = dfs(r1.node, -1, 0); cout << r2.dist << endl; return 0; }