結果

問題 No.845 最長の切符
ユーザー convexineqconvexineq
提出日時 2019-06-29 01:50:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 394 ms / 3,000 ms
コード長 818 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 91,044 KB
最終ジャッジ日時 2023-09-14 22:56:47
合計ジャッジ時間 5,670 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,088 KB
testcase_01 AC 73 ms
75,192 KB
testcase_02 AC 82 ms
76,684 KB
testcase_03 AC 71 ms
71,308 KB
testcase_04 AC 71 ms
71,416 KB
testcase_05 AC 71 ms
71,292 KB
testcase_06 AC 71 ms
71,416 KB
testcase_07 AC 72 ms
71,280 KB
testcase_08 AC 94 ms
76,800 KB
testcase_09 AC 77 ms
76,152 KB
testcase_10 AC 99 ms
77,028 KB
testcase_11 AC 92 ms
76,568 KB
testcase_12 AC 100 ms
76,964 KB
testcase_13 AC 86 ms
76,736 KB
testcase_14 AC 90 ms
76,832 KB
testcase_15 AC 146 ms
81,140 KB
testcase_16 AC 383 ms
91,008 KB
testcase_17 AC 163 ms
81,212 KB
testcase_18 AC 210 ms
84,524 KB
testcase_19 AC 123 ms
79,248 KB
testcase_20 AC 394 ms
91,044 KB
testcase_21 AC 302 ms
91,000 KB
testcase_22 AC 157 ms
81,500 KB
testcase_23 AC 118 ms
78,568 KB
testcase_24 AC 391 ms
90,980 KB
testcase_25 AC 73 ms
71,280 KB
testcase_26 AC 132 ms
90,828 KB
testcase_27 AC 72 ms
71,100 KB
testcase_28 AC 138 ms
90,912 KB
testcase_29 AC 74 ms
71,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!


n,m = [int(i) for i in input().split()]
lrp = [[int(i) for i in input().split()] for _ in range(m)]
g = [[1e9]*n for _ in range(n)]
for l,r,p in lrp:
    if g[l-1][r-1] == 1e9: g[l-1][r-1] = p
    else: g[l-1][r-1] = max(g[l-1][r-1],p)
    if g[r-1][l-1] == 1e9: g[r-1][l-1] = p
    else: g[r-1][l-1] = max(g[r-1][l-1],p)

L = 1<<(n)
dp = [[-1]*16 for _ in range(L)]
#dp[i][j]: 位置i, last=j

for i in range(n): dp[1<<i][i] = 0

for i in range(L):
    for now in range(n):
        if i & (1 << now) == 0: continue
        if dp[i][now] < 0: continue
        for j in range(n):
            if i&(1 << j) != 0: continue
            if g[j][now] == 1e9: continue
            dp[i^(1 << j)][j] = max(dp[i^(1 << j)][j], dp[i][now] + g[j][now])
    

print(max(max(i) for i in dp))




0