結果

問題 No.845 最長の切符
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-07-07 17:18:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,272 ms / 3,000 ms
コード長 532 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 272,424 KB
最終ジャッジ日時 2024-04-15 07:57:16
合計ジャッジ時間 13,203 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
55,468 KB
testcase_01 AC 48 ms
55,632 KB
testcase_02 AC 45 ms
55,500 KB
testcase_03 AC 45 ms
56,028 KB
testcase_04 AC 45 ms
55,816 KB
testcase_05 AC 45 ms
56,056 KB
testcase_06 AC 45 ms
56,256 KB
testcase_07 AC 44 ms
55,620 KB
testcase_08 AC 68 ms
71,408 KB
testcase_09 AC 51 ms
63,596 KB
testcase_10 AC 118 ms
78,636 KB
testcase_11 AC 77 ms
73,916 KB
testcase_12 AC 97 ms
77,232 KB
testcase_13 AC 69 ms
72,192 KB
testcase_14 AC 69 ms
72,260 KB
testcase_15 AC 444 ms
111,640 KB
testcase_16 AC 2,272 ms
271,712 KB
testcase_17 AC 467 ms
112,680 KB
testcase_18 AC 983 ms
165,336 KB
testcase_19 AC 244 ms
91,552 KB
testcase_20 AC 2,201 ms
271,312 KB
testcase_21 AC 1,607 ms
268,984 KB
testcase_22 AC 452 ms
112,752 KB
testcase_23 AC 152 ms
82,300 KB
testcase_24 AC 2,211 ms
272,424 KB
testcase_25 AC 46 ms
54,700 KB
testcase_26 AC 44 ms
56,396 KB
testcase_27 AC 45 ms
55,568 KB
testcase_28 AC 57 ms
65,948 KB
testcase_29 AC 45 ms
56,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections, functools

n, m = map(int, input().split())
d = [[-1] * n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = d[b][a] = max(d[a][b], c)

@functools.lru_cache(maxsize=None)
def f(current, history):
    ans = 0
    for nxt in range(n):
        if history & (1 << nxt) == 0 and d[current][nxt] > 0:
            ans = max(ans, f(nxt, history | (1 << current)) + d[current][nxt])
    return ans

ans = max(f(current, 0) for current in range(n))
print(ans)
0