結果

問題 No.845 最長の切符
ユーザー mkawa2mkawa2
提出日時 2019-07-11 21:52:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,840 ms / 3,000 ms
コード長 743 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,388 KB
実行使用メモリ 85,304 KB
最終ジャッジ日時 2024-04-25 22:53:31
合計ジャッジ時間 8,227 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,176 KB
testcase_01 AC 42 ms
54,912 KB
testcase_02 AC 38 ms
55,364 KB
testcase_03 AC 37 ms
54,216 KB
testcase_04 AC 38 ms
54,260 KB
testcase_05 AC 39 ms
53,928 KB
testcase_06 AC 38 ms
54,664 KB
testcase_07 AC 38 ms
55,112 KB
testcase_08 AC 50 ms
66,548 KB
testcase_09 AC 38 ms
54,740 KB
testcase_10 AC 84 ms
76,540 KB
testcase_11 AC 56 ms
66,872 KB
testcase_12 AC 64 ms
71,792 KB
testcase_13 AC 54 ms
66,148 KB
testcase_14 AC 54 ms
66,560 KB
testcase_15 AC 167 ms
78,728 KB
testcase_16 AC 1,840 ms
85,304 KB
testcase_17 AC 480 ms
78,584 KB
testcase_18 AC 376 ms
80,836 KB
testcase_19 AC 151 ms
77,668 KB
testcase_20 AC 559 ms
85,260 KB
testcase_21 AC 412 ms
85,020 KB
testcase_22 AC 423 ms
78,396 KB
testcase_23 AC 154 ms
77,180 KB
testcase_24 AC 1,534 ms
84,940 KB
testcase_25 AC 37 ms
54,736 KB
testcase_26 AC 43 ms
62,656 KB
testcase_27 AC 37 ms
55,256 KB
testcase_28 AC 43 ms
63,860 KB
testcase_29 AC 35 ms
54,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)

def dfs(i, s=0, d=0):
    s += 2 ** i
#    print(i,format(s,"b"),d,memo)
    if memo[i][s] > -1:
        return memo[i][s]+d
    memo[i][s]=-d
    mx = d
    for ki in to[i]:
        if (s >> ki) & 1: continue
        tmp = dfs(ki, s, d + ds[i][ki])
        if tmp > mx:
            mx = tmp
    memo[i][s] += mx
    return mx

n, m = map(int, input().split())
to = defaultdict(list)
ds = [[-1] * n for _ in range(n)]
memo = [[-1] * (2 ** n) for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
    ds[a][b] = ds[b][a] = max(ds[a][b], c)

print(max(dfs(i) for i in range(n)))
0