結果

問題 No.845 最長の切符
ユーザー mkawa2mkawa2
提出日時 2019-07-11 16:21:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 516 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 80,768 KB
最終ジャッジ日時 2024-04-25 10:56:00
合計ジャッジ時間 4,124 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
53,632 KB
testcase_01 AC 48 ms
54,144 KB
testcase_02 AC 47 ms
53,504 KB
testcase_03 WA -
testcase_04 AC 47 ms
53,632 KB
testcase_05 AC 41 ms
53,888 KB
testcase_06 AC 42 ms
53,632 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 44 ms
53,504 KB
testcase_26 AC 42 ms
53,632 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

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