結果
| 問題 |
No.845 最長の切符
|
| コンテスト | |
| ユーザー |
neko_the_shadow
|
| 提出日時 | 2019-07-07 17:18:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,733 ms / 3,000 ms |
| コード長 | 532 bytes |
| コンパイル時間 | 1,344 ms |
| コンパイル使用メモリ | 82,172 KB |
| 実行使用メモリ | 271,848 KB |
| 最終ジャッジ日時 | 2024-10-04 23:39:06 |
| 合計ジャッジ時間 | 11,547 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
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)
neko_the_shadow