結果

問題 No.845 最長の切符
ユーザー titiatitia
提出日時 2019-06-28 23:23:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 684 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 695,512 KB
最終ジャッジ日時 2023-09-14 22:42:23
合計ジャッジ時間 6,587 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
72,268 KB
testcase_01 AC 107 ms
72,336 KB
testcase_02 AC 108 ms
72,272 KB
testcase_03 WA -
testcase_04 AC 110 ms
72,672 KB
testcase_05 AC 113 ms
72,220 KB
testcase_06 AC 108 ms
72,064 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 125 ms
77,648 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]=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(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