結果

問題 No.3113 The farthest point
ユーザー わん
提出日時 2025-05-20 00:02:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 595 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 81,800 KB
実行使用メモリ 109,192 KB
最終ジャッジ日時 2025-05-20 00:02:38
合計ジャッジ時間 10,238 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

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

mx_cst = mx_idx = 0
stk = [(0, -1, 0)]
while stk:
  c, p, d = stk.pop()
  if mx_cst < d:
    mx_cst = d
    mx_idx = c
  for t, w in es[c]:
    if t == p: continue
    stk.append((t, c, max(0, d+w)))

mx_cst1 = mx_idx1 = 0
stk = [(mx_idx, -1, 0)]
while stk:
  c, p, d = stk.pop()
  if mx_cst1 < d:
    mx_cst1 = d
    mx_idx1 = c
  for t, w in es[c]:
    if t == p: continue
    stk.append((t, c, max(0, d+w)))

print(mx_cst1)
0