結果

問題 No.845 最長の切符
ユーザー stngstng
提出日時 2022-07-16 18:27:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,102 bytes
コンパイル時間 1,442 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 90,840 KB
最終ジャッジ日時 2023-09-11 03:51:47
合計ジャッジ時間 7,725 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,396 KB
testcase_01 AC 118 ms
76,580 KB
testcase_02 AC 99 ms
76,704 KB
testcase_03 WA -
testcase_04 AC 83 ms
76,264 KB
testcase_05 AC 76 ms
71,144 KB
testcase_06 AC 76 ms
71,148 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 93 ms
76,464 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 77 ms
71,280 KB
testcase_26 AC 453 ms
90,816 KB
testcase_27 AC 78 ms
71,204 KB
testcase_28 AC 468 ms
90,840 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 = [[0]*V for i in range(2**V)] # dpの長さは2^V必要
#dp[0][0] = 0 # 0から出発するのでdp[0][0]を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