結果

問題 No.845 最長の切符
ユーザー tktk_snsntktk_snsn
提出日時 2020-06-05 18:50:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 367 ms / 3,000 ms
コード長 715 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 90,740 KB
最終ジャッジ日時 2023-08-22 10:32:10
合計ジャッジ時間 6,731 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,104 KB
testcase_01 AC 94 ms
76,352 KB
testcase_02 AC 96 ms
76,108 KB
testcase_03 AC 73 ms
71,112 KB
testcase_04 AC 77 ms
75,488 KB
testcase_05 AC 72 ms
71,124 KB
testcase_06 AC 73 ms
71,212 KB
testcase_07 AC 74 ms
70,916 KB
testcase_08 AC 93 ms
76,384 KB
testcase_09 AC 81 ms
76,060 KB
testcase_10 AC 99 ms
76,600 KB
testcase_11 AC 90 ms
76,336 KB
testcase_12 AC 93 ms
76,588 KB
testcase_13 AC 89 ms
76,424 KB
testcase_14 AC 94 ms
75,968 KB
testcase_15 AC 142 ms
80,052 KB
testcase_16 AC 367 ms
90,468 KB
testcase_17 AC 149 ms
80,316 KB
testcase_18 AC 198 ms
83,888 KB
testcase_19 AC 117 ms
78,644 KB
testcase_20 AC 361 ms
90,488 KB
testcase_21 AC 359 ms
90,704 KB
testcase_22 AC 148 ms
79,912 KB
testcase_23 AC 111 ms
77,540 KB
testcase_24 AC 362 ms
90,464 KB
testcase_25 AC 72 ms
70,920 KB
testcase_26 AC 265 ms
90,488 KB
testcase_27 AC 73 ms
70,928 KB
testcase_28 AC 288 ms
90,740 KB
testcase_29 AC 76 ms
71,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
inf = 10**18
G = [[inf] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if G[a][b] > -c:
        G[a][b] = -c
        G[b][a] = -c

dp = [[inf] * N for _ in range(1 << N)]
for i in range(N):
    dp[1 << i][i] = 0

for bit in range(1 << N):
    for i in range(N):
        if (bit >> i) & 1:
            for j in range(N):
                if (bit >> j) & 1:
                    continue
                if G[i][j] < inf:
                    bit_next = bit | (1 << j)
                    dp[bit_next][j] = min(dp[bit_next][j], dp[bit][i] + G[i][j])
ans = inf
for i in range(1 << N):
    ans = min(ans, min(dp[i]))
print(-ans)
0