結果

問題 No.845 最長の切符
ユーザー mkawa2mkawa2
提出日時 2019-07-12 10:59:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,453 ms / 3,000 ms
コード長 618 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 92,136 KB
最終ジャッジ日時 2023-08-10 20:17:55
合計ジャッジ時間 9,265 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,388 KB
testcase_01 AC 87 ms
71,456 KB
testcase_02 AC 118 ms
77,816 KB
testcase_03 AC 84 ms
71,516 KB
testcase_04 AC 84 ms
71,796 KB
testcase_05 AC 84 ms
71,628 KB
testcase_06 AC 87 ms
71,580 KB
testcase_07 AC 85 ms
71,580 KB
testcase_08 AC 108 ms
77,900 KB
testcase_09 AC 90 ms
76,632 KB
testcase_10 AC 113 ms
78,372 KB
testcase_11 AC 104 ms
77,428 KB
testcase_12 AC 108 ms
77,788 KB
testcase_13 AC 102 ms
77,480 KB
testcase_14 AC 112 ms
78,132 KB
testcase_15 AC 176 ms
81,080 KB
testcase_16 AC 1,453 ms
92,136 KB
testcase_17 AC 412 ms
81,104 KB
testcase_18 AC 330 ms
84,480 KB
testcase_19 AC 183 ms
79,604 KB
testcase_20 AC 469 ms
92,036 KB
testcase_21 AC 350 ms
91,616 KB
testcase_22 AC 349 ms
80,960 KB
testcase_23 AC 163 ms
78,844 KB
testcase_24 AC 1,078 ms
91,796 KB
testcase_25 AC 82 ms
71,392 KB
testcase_26 AC 176 ms
91,796 KB
testcase_27 AC 83 ms
71,544 KB
testcase_28 AC 248 ms
91,968 KB
testcase_29 AC 84 ms
71,508 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):
    dps=dp[s]
    for cur in range(n):
        if s >> cur & 1 == 0: continue
        ps=s - (1 << cur)
        dpps=dp[ps]
        dsc=ds[cur]
        dps[cur] = max([dps[cur]] + [dpps[pre] + dsc[pre] for pre in to[cur] if (s >> pre) & 1])
print(max(dp[-1]))
0