結果

問題 No.845 最長の切符
ユーザー brthyyjpbrthyyjp
提出日時 2021-09-27 13:10:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,301 ms / 3,000 ms
コード長 689 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 91,108 KB
最終ジャッジ日時 2023-09-20 13:31:58
合計ジャッジ時間 8,248 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,344 KB
testcase_01 AC 75 ms
71,328 KB
testcase_02 AC 92 ms
76,780 KB
testcase_03 AC 75 ms
71,272 KB
testcase_04 AC 74 ms
71,132 KB
testcase_05 AC 75 ms
71,440 KB
testcase_06 AC 74 ms
71,284 KB
testcase_07 AC 73 ms
71,572 KB
testcase_08 AC 92 ms
76,872 KB
testcase_09 AC 78 ms
75,980 KB
testcase_10 AC 94 ms
76,908 KB
testcase_11 AC 88 ms
76,956 KB
testcase_12 AC 97 ms
76,632 KB
testcase_13 AC 90 ms
76,644 KB
testcase_14 AC 92 ms
76,792 KB
testcase_15 AC 154 ms
80,428 KB
testcase_16 AC 1,301 ms
91,108 KB
testcase_17 AC 412 ms
80,664 KB
testcase_18 AC 299 ms
83,732 KB
testcase_19 AC 147 ms
77,020 KB
testcase_20 AC 415 ms
90,696 KB
testcase_21 AC 299 ms
91,080 KB
testcase_22 AC 376 ms
80,244 KB
testcase_23 AC 150 ms
76,964 KB
testcase_24 AC 1,123 ms
90,840 KB
testcase_25 AC 73 ms
71,564 KB
testcase_26 AC 144 ms
90,024 KB
testcase_27 AC 73 ms
71,624 KB
testcase_28 AC 168 ms
90,972 KB
testcase_29 AC 73 ms
71,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    a, b =a-1, b-1
    g[a].append((c, b))
    g[b].append((c,a))

dp = [[-1]*n for i in range(1<<n)]
for i in range(n):
    dp[1<<i][i] = 0
for s in range(1<<n):
    for v in range(n):
        if not ((s>>v)&1):
            continue
        for c, u in g[v]:
            if (s>>u)&1:
                continue
            ns = s|(1<<u)
            dp[ns][u] = max(dp[ns][u], dp[s][v]+c)
ans = 0
for s in range(1<<n):
    for v in range(n):
        ans = max(ans, dp[s][v])
print(ans)
0