結果
問題 |
No.845 最長の切符
|
ユーザー |
![]() |
提出日時 | 2019-06-28 23:20:37 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 647 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 82,036 KB |
実行使用メモリ | 720,988 KB |
最終ジャッジ日時 | 2024-07-02 05:11:06 |
合計ジャッジ時間 | 5,656 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 WA * 3 MLE * 1 -- * 19 |
ソースコード
import sys input = sys.stdin.readline N,M=map(int,input().split()) L=[list(map(int,input().split())) for i in range(M)] LLIST=[[-1]*(N+1) for i in range(N+1)] for x,y,z in L: LLIST[x][y]=z LLIST[y][x]=z from functools import lru_cache @lru_cache(maxsize=None) def calc(USED,LAST,DIS): #print(bin(USED),LAST,DIS) ANS=DIS for i in range(1,N+1): if USED & (1<<i) !=0: continue if LLIST[LAST][i]==-1: continue USED2=USED+(1<<i) ANS=max(ANS,calc(USED2,i,DIS+LLIST[LAST][i])) return ANS ANS=0 for i in range(1,N+1): ANS=max(ANS,calc(1<<i,i,0)) print(ANS)