結果
| 問題 | No.3113 The farthest point |
| コンテスト | |
| ユーザー |
みどりむし🦠
|
| 提出日時 | 2025-04-19 14:04:56 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,012 bytes |
| 記録 | |
| コンパイル時間 | 3,633 ms |
| コンパイル使用メモリ | 280,436 KB |
| 実行使用メモリ | 17,996 KB |
| 最終ジャッジ日時 | 2025-04-19 14:05:22 |
| 合計ジャッジ時間 | 26,542 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 15 WA * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Edge {
int to;
T cost;
};
constexpr long INF64 = 1L << 60;
using Graph = vector<vector<Edge<long long>>>;
template <typename T>
pair<T, int> dfs(const Graph &G, int u, int par) {
pair<T, int> ret = make_pair(-INF64, u);
for (auto e : G[u]) {
if (e.to == par) continue;
auto next = dfs<T>(G, e.to, u);
next.first += e.cost;
std::cerr << next.first << "\n";
ret = max(ret, next);
}
if(ret.first == -INF64) ret.first = 0;
return ret;
}
template <typename T>
T tree_diamiter(const Graph &G) {
pair<T, int> p = dfs<T>(G, 0, -1);
pair<T, int> q = dfs<T>(G, p.second, -1);
return q.first;
}
int main() {
int n; std::cin >> n;
Graph G(n);
for(int i : std::views::iota(0, n - 1)) {
long u, v, w; std::cin >> u >> v >> w; --u, --v;
G[u].emplace_back(v, w);
G[v].emplace_back(u, w);
}
std::cout << tree_diamiter<long>(G) << "\n";
}
みどりむし🦠