結果

問題 No.845 最長の切符
ユーザー stngstng
提出日時 2022-07-16 18:51:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 698 ms / 3,000 ms
コード長 1,159 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 102,032 KB
最終ジャッジ日時 2023-09-11 04:20:30
合計ジャッジ時間 8,198 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,304 KB
testcase_01 AC 93 ms
76,652 KB
testcase_02 AC 101 ms
76,492 KB
testcase_03 AC 79 ms
71,288 KB
testcase_04 AC 86 ms
76,316 KB
testcase_05 AC 77 ms
71,392 KB
testcase_06 AC 77 ms
71,452 KB
testcase_07 AC 78 ms
71,564 KB
testcase_08 AC 125 ms
77,808 KB
testcase_09 AC 95 ms
76,880 KB
testcase_10 AC 141 ms
78,180 KB
testcase_11 AC 98 ms
76,784 KB
testcase_12 AC 129 ms
77,980 KB
testcase_13 AC 101 ms
76,912 KB
testcase_14 AC 124 ms
77,540 KB
testcase_15 AC 212 ms
83,584 KB
testcase_16 AC 592 ms
101,636 KB
testcase_17 AC 181 ms
80,808 KB
testcase_18 AC 290 ms
88,816 KB
testcase_19 AC 148 ms
79,036 KB
testcase_20 AC 628 ms
101,952 KB
testcase_21 AC 698 ms
102,032 KB
testcase_22 AC 179 ms
80,716 KB
testcase_23 AC 130 ms
78,156 KB
testcase_24 AC 608 ms
102,028 KB
testcase_25 AC 77 ms
71,216 KB
testcase_26 AC 435 ms
90,748 KB
testcase_27 AC 76 ms
71,352 KB
testcase_28 AC 507 ms
91,004 KB
testcase_29 AC 78 ms
71,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
V = n
E = m

G = [[-float('inf')]*V for i in range(V)] # 存在しないパスはinfになるように、最初にすべてinfにしておく
for i in range(E):
    s,t,d = map(int,input().split())
    s -= 1
    t -= 1
    G[s][t] = max(d,G[s][t]) # s,tは0以上V-1以下なので、デクリメントの必要はない
    G[t][s] = max(d,G[s][t]) # s,tは0以上V-1以下なので、デクリメントの必要はない
dp = [[-float('inf')]*V for i in range(2**V)] # dpの長さは2^V必要

for i in range(V):
    dp[2**i][i] = 0

for S in range(2**V): # Sは集合をbitで表している
    for v in range(V): # vは配られる側の要素を表している
        for u in range(V): # uは配る側の要素を表している
            if not (S >> u) & 1: # ①
                continue
            if (S >> v) & 1 == 0: # ②
                if dp[S][u] + G[u][v] > dp[S | (1 << v)][v]:
                    #print(dp[S][u],u,v)
                    dp[S | (1 << v)][v] = dp[S][u] + G[u][v] # ③
#print(dp)
#print(G)
ans = 0
for i in range(2**V):
    for j in range(V):
        ans = max(ans,dp[i][j])

print(ans)
0