結果

問題 No.845 最長の切符
ユーザー titiatitia
提出日時 2019-06-28 23:20:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 647 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 782,932 KB
最終ジャッジ日時 2023-09-14 22:41:53
合計ジャッジ時間 6,889 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
72,788 KB
testcase_01 AC 108 ms
71,880 KB
testcase_02 AC 108 ms
71,900 KB
testcase_03 WA -
testcase_04 AC 109 ms
71,972 KB
testcase_05 AC 107 ms
71,968 KB
testcase_06 AC 110 ms
71,928 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 122 ms
77,244 KB
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0