結果

問題 No.3113 The farthest point
ユーザー issaimaru
提出日時 2025-04-19 22:34:56
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 627 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 80,984 KB
最終ジャッジ日時 2025-04-19 22:35:26
合計ジャッジ時間 29,960 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(1 << 25)

N = int(input())
from collections import defaultdict

tree = defaultdict(list)

for _ in range(N - 1):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

def dfs(node, parent, dist):
    farthest = (dist, node)
    for neighbor, weight in tree[node]:
        if neighbor != parent:
            candidate = dfs(neighbor, node, dist + weight)
            if candidate[0] > farthest[0]:
                farthest = candidate
    return farthest

_, farthest_node = dfs(1, -1, 0)

max_dist, _ = dfs(farthest_node, -1, 0)

print(max(0, max_dist))
0