結果

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

ソースコード

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, 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, d+w))

print(mx_cst1)
0