結果

問題 No.845 最長の切符
ユーザー tpynerivertpyneriver
提出日時 2019-06-28 22:20:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 487 ms / 3,000 ms
コード長 585 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 91,156 KB
最終ジャッジ日時 2023-09-14 22:08:37
合計ジャッジ時間 6,634 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,392 KB
testcase_01 AC 81 ms
76,692 KB
testcase_02 AC 94 ms
76,776 KB
testcase_03 AC 71 ms
71,140 KB
testcase_04 AC 75 ms
76,168 KB
testcase_05 AC 73 ms
71,292 KB
testcase_06 AC 75 ms
71,292 KB
testcase_07 AC 74 ms
71,380 KB
testcase_08 AC 94 ms
76,864 KB
testcase_09 AC 83 ms
76,764 KB
testcase_10 AC 110 ms
77,748 KB
testcase_11 AC 92 ms
76,840 KB
testcase_12 AC 99 ms
76,888 KB
testcase_13 AC 95 ms
76,888 KB
testcase_14 AC 98 ms
76,664 KB
testcase_15 AC 159 ms
80,548 KB
testcase_16 AC 476 ms
90,980 KB
testcase_17 AC 171 ms
80,564 KB
testcase_18 AC 248 ms
83,912 KB
testcase_19 AC 128 ms
78,832 KB
testcase_20 AC 480 ms
90,780 KB
testcase_21 AC 453 ms
91,156 KB
testcase_22 AC 167 ms
80,448 KB
testcase_23 AC 122 ms
78,316 KB
testcase_24 AC 487 ms
90,852 KB
testcase_25 AC 70 ms
71,452 KB
testcase_26 AC 326 ms
91,124 KB
testcase_27 AC 72 ms
71,292 KB
testcase_28 AC 365 ms
90,992 KB
testcase_29 AC 71 ms
71,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())

Edge = [[0]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    Edge[a][b] = max(Edge[a][b], c)
    Edge[b][a] = Edge[a][b]


dp = [[0]*N for _ in range(2**N)]

for s in range(1, 2**N):
    for i in range(N):
        if not 2**i & s:
            continue
        res = dp[s][i]
        for j in range(N):
            if 2**j & s or not Edge[i][j]:
                continue
            dp[s|2**j][j] = max(dp[s|2**j][j], Edge[i][j] + res)

ans = 0
for d in dp:
    ans = max(ans, max(d))
print(ans)
0