結果

問題 No.845 最長の切符
ユーザー titiatitia
提出日時 2019-06-28 23:33:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,328 ms / 3,000 ms
コード長 707 bytes
コンパイル時間 651 ms
コンパイル使用メモリ 86,644 KB
実行使用メモリ 275,196 KB
最終ジャッジ日時 2023-09-14 22:46:07
合計ジャッジ時間 16,045 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
71,652 KB
testcase_01 AC 108 ms
72,016 KB
testcase_02 AC 111 ms
71,900 KB
testcase_03 AC 103 ms
71,888 KB
testcase_04 AC 108 ms
71,988 KB
testcase_05 AC 107 ms
71,936 KB
testcase_06 AC 105 ms
71,648 KB
testcase_07 AC 107 ms
71,936 KB
testcase_08 AC 132 ms
77,096 KB
testcase_09 AC 114 ms
75,668 KB
testcase_10 AC 196 ms
80,548 KB
testcase_11 AC 148 ms
77,908 KB
testcase_12 AC 170 ms
79,564 KB
testcase_13 AC 132 ms
77,096 KB
testcase_14 AC 131 ms
77,560 KB
testcase_15 AC 510 ms
115,248 KB
testcase_16 AC 2,284 ms
274,868 KB
testcase_17 AC 523 ms
113,896 KB
testcase_18 AC 1,004 ms
168,628 KB
testcase_19 AC 313 ms
93,052 KB
testcase_20 AC 2,148 ms
272,884 KB
testcase_21 AC 1,713 ms
272,180 KB
testcase_22 AC 537 ms
113,652 KB
testcase_23 AC 240 ms
86,528 KB
testcase_24 AC 2,328 ms
275,196 KB
testcase_25 AC 109 ms
72,084 KB
testcase_26 AC 106 ms
72,092 KB
testcase_27 AC 110 ms
71,636 KB
testcase_28 AC 122 ms
77,324 KB
testcase_29 AC 113 ms
71,992 KB
権限があれば一括ダウンロードができます

ソースコード

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):
    #print(bin(USED),LAST,DIS)
    ANS=0
    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)+LLIST[LAST][i])

    return ANS

ANS=0
for i in range(N):
    ANS=max(ANS,calc(1<<i,i))

print(ANS)
0