結果

問題 No.845 最長の切符
ユーザー H3PO4H3PO4
提出日時 2021-02-23 10:08:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,255 ms / 3,000 ms
コード長 541 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 84,044 KB
最終ジャッジ日時 2023-10-22 04:57:40
合計ジャッジ時間 6,760 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,512 KB
testcase_01 AC 40 ms
53,512 KB
testcase_02 AC 62 ms
66,596 KB
testcase_03 AC 41 ms
53,536 KB
testcase_04 AC 40 ms
53,536 KB
testcase_05 AC 41 ms
53,536 KB
testcase_06 AC 40 ms
53,536 KB
testcase_07 AC 41 ms
53,536 KB
testcase_08 AC 57 ms
64,480 KB
testcase_09 AC 47 ms
59,576 KB
testcase_10 AC 61 ms
66,524 KB
testcase_11 AC 55 ms
64,260 KB
testcase_12 AC 59 ms
66,540 KB
testcase_13 AC 54 ms
64,268 KB
testcase_14 AC 59 ms
66,552 KB
testcase_15 AC 117 ms
72,704 KB
testcase_16 AC 1,255 ms
84,044 KB
testcase_17 AC 390 ms
74,220 KB
testcase_18 AC 260 ms
76,512 KB
testcase_19 AC 113 ms
68,572 KB
testcase_20 AC 352 ms
83,916 KB
testcase_21 AC 232 ms
83,904 KB
testcase_22 AC 340 ms
73,152 KB
testcase_23 AC 121 ms
68,572 KB
testcase_24 AC 1,069 ms
83,952 KB
testcase_25 AC 39 ms
53,536 KB
testcase_26 AC 83 ms
74,840 KB
testcase_27 AC 39 ms
53,536 KB
testcase_28 AC 110 ms
83,972 KB
testcase_29 AC 39 ms
53,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append((b, c))
    G[b].append((a, c))

dp = [[0] * (1 << N) for _ in range(N)]
for b in range(1, 1 << N):
    for v in range(N):
        if b >> v & 1:
            dp_vb = dp[v][b]
            for x, c in G[v]:
                if b >> x & 1:
                    continue
                dp[x][b | (1 << x)] = max(dp[x][b | (1 << x)], dp_vb + c)
ans = max(max(dpx) for dpx in dp)
print(ans)
0