結果

問題 No.845 最長の切符
ユーザー stngstng
提出日時 2022-07-16 18:37:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,085 bytes
コンパイル時間 454 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 102,136 KB
最終ジャッジ日時 2023-09-11 04:03:45
合計ジャッジ時間 8,408 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,152 KB
testcase_01 AC 88 ms
76,456 KB
testcase_02 AC 100 ms
76,708 KB
testcase_03 WA -
testcase_04 AC 83 ms
76,116 KB
testcase_05 AC 76 ms
71,448 KB
testcase_06 AC 76 ms
71,476 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 92 ms
76,636 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 74 ms
71,516 KB
testcase_26 AC 439 ms
90,752 KB
testcase_27 AC 74 ms
71,008 KB
testcase_28 AC 508 ms
90,984 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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] = d # s,tは0以上V-1以下なので、デクリメントの必要はない
    G[t][s] = d # 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:# and S != 0: # ①
                continue
            if (S >> v) & 1 == 0: # ②
                if dp[S][u] + G[u][v] > dp[S | (1 << v)][v]:
                    dp[S | (1 << v)][v] = dp[S][u] + G[u][v] # ③

ans = 0
for i in range(2**V):
    for j in range(V):
        ans = max(ans,dp[i][j])

print(ans)
0