結果

問題 No.845 最長の切符
ユーザー mkawa2
提出日時 2019-07-11 16:22:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 556 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 850,176 KB
最終ジャッジ日時 2024-11-07 21:39:06
合計ジャッジ時間 3,868 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 1 MLE * 1 -- * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

def dfs(i, oi=-1, d=0):
    if len(to[i]) == 1:
        if to[i][0][0] == oi:
            return d
    mx = 0
    for ki, kd in to[i]:
        if ki == oi: continue
        tmp = dfs(ki, i, d + kd)
        if tmp > mx:
            mx = tmp
    return mx

n, m = map(int, input().split())
to = defaultdict(list)
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append([b, c])
    to[b].append([a, c])
print(max(dfs(i) for i in range(n)))
0