結果

問題 No.845 最長の切符
ユーザー neterukunneterukun
提出日時 2019-06-30 14:48:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 490 ms / 3,000 ms
コード長 844 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 91,076 KB
最終ジャッジ日時 2023-09-20 07:42:51
合計ジャッジ時間 7,549 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,280 KB
testcase_01 AC 85 ms
75,616 KB
testcase_02 AC 101 ms
76,776 KB
testcase_03 AC 78 ms
71,356 KB
testcase_04 AC 82 ms
76,280 KB
testcase_05 AC 79 ms
71,540 KB
testcase_06 AC 77 ms
71,100 KB
testcase_07 AC 77 ms
71,100 KB
testcase_08 AC 98 ms
76,372 KB
testcase_09 AC 90 ms
76,364 KB
testcase_10 AC 112 ms
77,280 KB
testcase_11 AC 99 ms
76,768 KB
testcase_12 AC 101 ms
76,760 KB
testcase_13 AC 97 ms
76,732 KB
testcase_14 AC 100 ms
76,664 KB
testcase_15 AC 168 ms
80,276 KB
testcase_16 AC 485 ms
90,712 KB
testcase_17 AC 188 ms
80,964 KB
testcase_18 AC 239 ms
83,640 KB
testcase_19 AC 132 ms
78,400 KB
testcase_20 AC 463 ms
90,684 KB
testcase_21 AC 440 ms
90,708 KB
testcase_22 AC 182 ms
80,396 KB
testcase_23 AC 125 ms
78,112 KB
testcase_24 AC 490 ms
91,076 KB
testcase_25 AC 75 ms
71,356 KB
testcase_26 AC 348 ms
90,720 KB
testcase_27 AC 76 ms
71,124 KB
testcase_28 AC 383 ms
90,652 KB
testcase_29 AC 77 ms
71,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

graph = [[0]*n for i in range(n)]
for tmp1, tmp2, cost in info:
    tmp1 -= 1
    tmp2 -= 1
    graph[tmp1][tmp2] = max(graph[tmp1][tmp2], cost)
    graph[tmp2][tmp1] = max(graph[tmp2][tmp1], cost)

# dp[subset][j] := すでにsubsetの集合を訪れていて、最後に訪問したのがjのときの最大値
dp = [[0]*n for i in range(2**n)]
for subset in range(2**n):
    for j in range(n):
        if subset & 2**j != 0:
            for k in range(n):
                if subset & 2**k !=0 and graph[k][j] != 0:
                    # subsetにjとkを含んでいて、kとjは連結である
                    dp[subset][j] = max(dp[subset][j], dp[subset - 2**j][k] + graph[k][j])

ans = 0
for num in dp:
    ans = max(num + [ans])
print(ans)
0