結果

問題 No.845 最長の切符
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-07-07 17:18:39
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 2,079 ms / 3,000 ms
コード長 532 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 276,812 KB
最終ジャッジ日時 2023-07-27 21:21:39
合計ジャッジ時間 16,422 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
73,060 KB
testcase_01 AC 99 ms
72,864 KB
testcase_02 AC 98 ms
72,868 KB
testcase_03 AC 98 ms
72,844 KB
testcase_04 AC 97 ms
72,740 KB
testcase_05 AC 96 ms
72,888 KB
testcase_06 AC 95 ms
72,992 KB
testcase_07 AC 98 ms
72,872 KB
testcase_08 AC 123 ms
78,352 KB
testcase_09 AC 104 ms
77,288 KB
testcase_10 AC 159 ms
83,144 KB
testcase_11 AC 123 ms
78,360 KB
testcase_12 AC 143 ms
81,372 KB
testcase_13 AC 123 ms
78,616 KB
testcase_14 AC 121 ms
78,512 KB
testcase_15 AC 435 ms
115,308 KB
testcase_16 AC 1,998 ms
275,788 KB
testcase_17 AC 483 ms
116,624 KB
testcase_18 AC 983 ms
170,108 KB
testcase_19 AC 294 ms
95,368 KB
testcase_20 AC 2,031 ms
275,912 KB
testcase_21 AC 1,561 ms
272,856 KB
testcase_22 AC 499 ms
116,664 KB
testcase_23 AC 209 ms
85,536 KB
testcase_24 AC 2,079 ms
276,812 KB
testcase_25 AC 100 ms
72,860 KB
testcase_26 AC 100 ms
72,960 KB
testcase_27 AC 98 ms
73,244 KB
testcase_28 AC 109 ms
78,676 KB
testcase_29 AC 98 ms
73,136 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