結果
問題 | No.845 最長の切符 |
ユーザー |
![]() |
提出日時 | 2019-07-07 17:01:38 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 513 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 81,840 KB |
実行使用メモリ | 140,332 KB |
最終ジャッジ日時 | 2024-10-04 22:15:41 |
合計ジャッジ時間 | 6,802 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 WA * 8 TLE * 1 -- * 14 |
ソースコード
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)