結果

問題 No.845 最長の切符
ユーザー mkawa2mkawa2
提出日時 2019-07-12 10:51:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,899 ms / 3,000 ms
コード長 659 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 90,496 KB
最終ジャッジ日時 2024-04-28 13:15:37
合計ジャッジ時間 8,711 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
53,760 KB
testcase_01 AC 49 ms
54,400 KB
testcase_02 AC 88 ms
77,312 KB
testcase_03 AC 44 ms
53,760 KB
testcase_04 AC 43 ms
54,016 KB
testcase_05 AC 44 ms
53,760 KB
testcase_06 AC 43 ms
54,144 KB
testcase_07 AC 42 ms
53,504 KB
testcase_08 AC 69 ms
72,832 KB
testcase_09 AC 48 ms
61,184 KB
testcase_10 AC 80 ms
76,820 KB
testcase_11 AC 64 ms
68,992 KB
testcase_12 AC 80 ms
76,672 KB
testcase_13 AC 71 ms
67,328 KB
testcase_14 AC 83 ms
77,056 KB
testcase_15 AC 161 ms
79,744 KB
testcase_16 AC 1,899 ms
90,368 KB
testcase_17 AC 421 ms
80,256 KB
testcase_18 AC 345 ms
83,140 KB
testcase_19 AC 151 ms
77,964 KB
testcase_20 AC 532 ms
90,112 KB
testcase_21 AC 406 ms
90,368 KB
testcase_22 AC 393 ms
80,000 KB
testcase_23 AC 146 ms
77,056 KB
testcase_24 AC 1,333 ms
90,496 KB
testcase_25 AC 43 ms
53,760 KB
testcase_26 AC 159 ms
90,104 KB
testcase_27 AC 45 ms
53,760 KB
testcase_28 AC 283 ms
90,240 KB
testcase_29 AC 44 ms
53,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def f(n, m):
    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]))

n, m = map(int, input().split())
f(n, m)
0