結果
問題 |
No.3113 The farthest point
|
ユーザー |
|
提出日時 | 2025-04-19 03:34:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 558 ms / 2,000 ms |
コード長 | 425 bytes |
コンパイル時間 | 325 ms |
コンパイル使用メモリ | 82,316 KB |
実行使用メモリ | 109,644 KB |
最終ジャッジ日時 | 2025-04-19 03:34:42 |
合計ジャッジ時間 | 11,401 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
N = int(input()) G = [[] for _ in range(N)] for i in range(N-1): u, v, w = map(int, input().split()) G[u-1].append((v-1, w)) G[v-1].append((u-1, w)) ans = 0 def dfs(v, p): global ans res = [0, 0] for u, w in G[v]: if u == p: continue res.append(dfs(u, v) + w) res.sort(reverse=True) ans = max(ans, res[0] + res[1], res[0]) return res[0] dfs(0, -1) print(ans)