結果

問題 No.845 最長の切符
ユーザー mkawa2mkawa2
提出日時 2019-07-11 18:45:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 686 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 85,580 KB
最終ジャッジ日時 2024-04-25 15:16:16
合計ジャッジ時間 8,970 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,104 KB
testcase_01 AC 40 ms
55,720 KB
testcase_02 AC 43 ms
55,484 KB
testcase_03 AC 40 ms
54,252 KB
testcase_04 AC 41 ms
54,536 KB
testcase_05 AC 41 ms
54,852 KB
testcase_06 AC 41 ms
54,264 KB
testcase_07 WA -
testcase_08 AC 57 ms
67,072 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 41 ms
53,664 KB
testcase_26 AC 48 ms
63,816 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 41 ms
54,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)

def dfs(i, s=0, d=0):
    s += 2 ** i
    if memo[i][s] != -1:
        return memo[i][s]
    mx = d
    for ki in to[i]:
        if s >> ki & 1: continue
        tmp = dfs(ki, s, d + ds[i][ki])
        if tmp > mx:
            mx = tmp
    memo[i][s] = mx
    return mx

n, m = map(int, input().split())
to = defaultdict(list)
ds = [[-1] * n for _ in range(n)]
memo = [[-1] * (2 ** n) for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
    ds[a][b] = ds[b][a] = max(ds[a][b], c)

print(max(dfs(i) for i in range(n)))
0