結果

問題 No.3113 The farthest point
ユーザー ZOI-dayo
提出日時 2025-04-06 21:14:30
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 672 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 90,776 KB
実行使用メモリ 21,760 KB
最終ジャッジ日時 2025-04-06 21:14:39
合計ジャッジ時間 9,009 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

int main() {
  int n;
  std::cin >> n;
  std::vector adj(n, std::vector<std::pair<long long, int>>());
  for(int i = 0; i < n-1; i++) {
    int u, v, w;
    std::cin >> u >> v >> w;
    u--; v--;
    adj[u].emplace_back(w, v);
    adj[v].emplace_back(w, u);
  }
  auto dfs = [&](auto&& self, int v, int p) -> long long {
    long long res = 0;
    for(auto [w, u] : adj[v]) {
      if(u == p) continue;
      auto ans = self(self, u, v) + w;
      res = std::max(res, ans);
    }
    return res;
  };
  long long ans = 0;
  for(int i = 0; i < n; i++) {
    ans = std::max(ans, dfs(dfs, i, -1));
  }
  std::cout << ans << std::endl;
}
0