結果

問題 No.845 最長の切符
ユーザー mkawa2mkawa2
提出日時 2019-07-12 10:57:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,612 ms / 3,000 ms
コード長 574 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 90,608 KB
最終ジャッジ日時 2024-04-28 13:28:23
合計ジャッジ時間 7,607 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,592 KB
testcase_01 AC 43 ms
54,828 KB
testcase_02 AC 65 ms
76,832 KB
testcase_03 AC 40 ms
55,364 KB
testcase_04 AC 39 ms
55,752 KB
testcase_05 AC 38 ms
55,100 KB
testcase_06 AC 38 ms
54,376 KB
testcase_07 AC 38 ms
54,200 KB
testcase_08 AC 64 ms
72,860 KB
testcase_09 AC 46 ms
63,028 KB
testcase_10 AC 75 ms
77,180 KB
testcase_11 AC 58 ms
69,792 KB
testcase_12 AC 66 ms
76,920 KB
testcase_13 AC 57 ms
68,124 KB
testcase_14 AC 70 ms
77,404 KB
testcase_15 AC 134 ms
80,120 KB
testcase_16 AC 1,612 ms
90,608 KB
testcase_17 AC 364 ms
80,356 KB
testcase_18 AC 287 ms
83,404 KB
testcase_19 AC 129 ms
78,452 KB
testcase_20 AC 417 ms
90,440 KB
testcase_21 AC 333 ms
90,404 KB
testcase_22 AC 324 ms
80,108 KB
testcase_23 AC 130 ms
77,492 KB
testcase_24 AC 1,101 ms
90,264 KB
testcase_25 AC 37 ms
54,216 KB
testcase_26 AC 127 ms
90,316 KB
testcase_27 AC 38 ms
54,732 KB
testcase_28 AC 190 ms
90,476 KB
testcase_29 AC 38 ms
55,464 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
        ps=s - (1 << cur)
        dp[s][cur] = max([dp[s][cur]] + [dp[ps][pre] + ds[cur][pre] for pre in to[cur] if (s >> pre) & 1])
print(max(dp[-1]))
0