結果

問題 No.845 最長の切符
ユーザー mkawa2mkawa2
提出日時 2019-07-12 10:49:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,749 ms / 3,000 ms
コード長 560 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 90,888 KB
最終ジャッジ日時 2024-04-28 13:13:39
合計ジャッジ時間 7,965 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
54,472 KB
testcase_01 AC 43 ms
55,128 KB
testcase_02 AC 74 ms
77,124 KB
testcase_03 AC 44 ms
55,020 KB
testcase_04 AC 43 ms
54,788 KB
testcase_05 AC 44 ms
54,620 KB
testcase_06 AC 44 ms
53,804 KB
testcase_07 AC 44 ms
54,644 KB
testcase_08 AC 74 ms
73,368 KB
testcase_09 AC 48 ms
61,648 KB
testcase_10 AC 79 ms
76,804 KB
testcase_11 AC 63 ms
69,092 KB
testcase_12 AC 74 ms
76,656 KB
testcase_13 AC 60 ms
68,160 KB
testcase_14 AC 79 ms
77,072 KB
testcase_15 AC 151 ms
79,712 KB
testcase_16 AC 1,749 ms
90,888 KB
testcase_17 AC 405 ms
80,016 KB
testcase_18 AC 330 ms
83,540 KB
testcase_19 AC 142 ms
77,976 KB
testcase_20 AC 491 ms
90,260 KB
testcase_21 AC 388 ms
90,024 KB
testcase_22 AC 375 ms
80,316 KB
testcase_23 AC 138 ms
77,488 KB
testcase_24 AC 1,265 ms
90,084 KB
testcase_25 AC 43 ms
55,740 KB
testcase_26 AC 149 ms
90,656 KB
testcase_27 AC 42 ms
53,916 KB
testcase_28 AC 234 ms
90,292 KB
testcase_29 AC 42 ms
55,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

n, m = map(int, input().split())
to = defaultdict(list)
ds = [[-1] * n for _ in range(n)]
dp = [[0] * (n) for _ in range(2 ** 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)
for s in range(1, 2 ** n):
    for cur in range(n):
        if s >> cur & 1 == 0: continue
        dp[s][cur] = max([dp[s][cur]] + [dp[s - (1 << cur)][pre] + ds[cur][pre] for pre in to[cur] if (s >> pre) & 1])
print(max(dp[-1]))
0