結果

問題 No.845 最長の切符
ユーザー titiatitia
提出日時 2019-06-28 23:25:54
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 760 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 786,620 KB
最終ジャッジ日時 2023-09-14 22:42:43
合計ジャッジ時間 6,301 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
76,004 KB
testcase_01 AC 110 ms
71,792 KB
testcase_02 AC 108 ms
71,908 KB
testcase_03 AC 107 ms
71,792 KB
testcase_04 AC 108 ms
72,040 KB
testcase_05 AC 109 ms
71,900 KB
testcase_06 AC 106 ms
71,992 KB
testcase_07 AC 107 ms
71,872 KB
testcase_08 AC 148 ms
78,892 KB
testcase_09 AC 124 ms
77,388 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)]

for i in range(M):
    L[i][0]-=1
    L[i][1]-=1

LLIST=[[-1]*(N) for i in range(N)]

for x,y,z in L:
    LLIST[x][y]=max(LLIST[x][y],z)
    LLIST[y][x]=max(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(N):
        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(N):
    ANS=max(ANS,calc(1<<i,i,0))

print(ANS)

                
        
        
    
0