結果
問題 | No.845 最長の切符 |
ユーザー |
![]() |
提出日時 | 2019-07-07 17:15:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,393 ms / 3,000 ms |
コード長 | 595 bytes |
コンパイル時間 | 395 ms |
コンパイル使用メモリ | 82,180 KB |
実行使用メモリ | 199,560 KB |
最終ジャッジ日時 | 2024-10-04 23:32:32 |
合計ジャッジ時間 | 9,409 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
import collections 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) cache = {} def f(current, history): ky = (current, history) if ky in cache: return cache[ky] 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]) cache[ky] = ans return ans ans = max(f(current, 0) for current in range(n)) print(ans)