結果

問題 No.845 最長の切符
ユーザー 👑 rin204rin204
提出日時 2022-03-12 22:55:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 322 ms / 3,000 ms
コード長 611 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 81,584 KB
実行使用メモリ 89,288 KB
最終ジャッジ日時 2023-10-17 08:53:46
合計ジャッジ時間 4,966 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,408 KB
testcase_01 AC 43 ms
61,700 KB
testcase_02 AC 53 ms
66,264 KB
testcase_03 AC 36 ms
53,408 KB
testcase_04 AC 40 ms
59,636 KB
testcase_05 AC 36 ms
53,408 KB
testcase_06 AC 35 ms
53,408 KB
testcase_07 AC 35 ms
53,408 KB
testcase_08 AC 54 ms
66,284 KB
testcase_09 AC 49 ms
61,844 KB
testcase_10 AC 58 ms
68,448 KB
testcase_11 AC 53 ms
66,252 KB
testcase_12 AC 55 ms
66,264 KB
testcase_13 AC 52 ms
64,204 KB
testcase_14 AC 53 ms
66,264 KB
testcase_15 AC 101 ms
78,636 KB
testcase_16 AC 322 ms
89,016 KB
testcase_17 AC 112 ms
78,648 KB
testcase_18 AC 146 ms
81,988 KB
testcase_19 AC 75 ms
72,536 KB
testcase_20 AC 309 ms
89,152 KB
testcase_21 AC 303 ms
89,160 KB
testcase_22 AC 110 ms
78,636 KB
testcase_23 AC 77 ms
72,612 KB
testcase_24 AC 315 ms
89,040 KB
testcase_25 AC 36 ms
53,408 KB
testcase_26 AC 267 ms
89,288 KB
testcase_27 AC 37 ms
53,408 KB
testcase_28 AC 275 ms
89,288 KB
testcase_29 AC 36 ms
53,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
dist = [[-1 << 30] * n for _ in range(n)]
for i in range(n):
    dist[i][i] = 0
    
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    dist[a][b] = max(dist[a][b], c)
    dist[b][a] = max(dist[b][a], c)
    
dp = [[0] * n for _ in range(1 << n)]
for bit in range(1, 1 << n):
    for i in range(n):
        if not bit >> i & 1:
            continue
        for j in range(n):
            if i == j or not bit >> j & 1:
                continue
            dp[bit][j] = max(dp[bit][j], dp[bit ^ (1 << j)][i] + dist[i][j])
print(max(dp[-1]))
    
0