結果

問題 No.845 最長の切符
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-07-07 17:01:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 513 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 92,388 KB
最終ジャッジ日時 2024-04-15 07:22:59
合計ジャッジ時間 6,771 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
62,628 KB
testcase_01 AC 45 ms
55,948 KB
testcase_02 AC 46 ms
55,952 KB
testcase_03 WA -
testcase_04 AC 45 ms
56,792 KB
testcase_05 AC 45 ms
56,236 KB
testcase_06 AC 44 ms
55,456 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 57 ms
66,544 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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] = c
    d[b][a] = c


@functools.lru_cache()
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