結果

問題 No.845 最長の切符
ユーザー 👑 KazunKazun
提出日時 2022-02-16 03:18:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 547 ms / 3,000 ms
コード長 688 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 86,700 KB
実行使用メモリ 101,912 KB
最終ジャッジ日時 2023-09-11 17:06:16
合計ジャッジ時間 8,216 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,120 KB
testcase_01 AC 109 ms
76,440 KB
testcase_02 AC 102 ms
76,580 KB
testcase_03 AC 73 ms
71,296 KB
testcase_04 AC 75 ms
75,608 KB
testcase_05 AC 73 ms
71,112 KB
testcase_06 AC 72 ms
70,900 KB
testcase_07 AC 74 ms
71,272 KB
testcase_08 AC 118 ms
77,728 KB
testcase_09 AC 83 ms
76,572 KB
testcase_10 AC 139 ms
78,172 KB
testcase_11 AC 89 ms
76,552 KB
testcase_12 AC 138 ms
78,536 KB
testcase_13 AC 94 ms
76,324 KB
testcase_14 AC 129 ms
77,656 KB
testcase_15 AC 191 ms
83,128 KB
testcase_16 AC 398 ms
101,828 KB
testcase_17 AC 145 ms
80,616 KB
testcase_18 AC 225 ms
89,008 KB
testcase_19 AC 125 ms
78,656 KB
testcase_20 AC 450 ms
101,808 KB
testcase_21 AC 547 ms
101,912 KB
testcase_22 AC 149 ms
80,656 KB
testcase_23 AC 114 ms
78,052 KB
testcase_24 AC 414 ms
101,900 KB
testcase_25 AC 72 ms
71,432 KB
testcase_26 AC 316 ms
90,716 KB
testcase_27 AC 71 ms
71,432 KB
testcase_28 AC 366 ms
90,784 KB
testcase_29 AC 70 ms
71,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import product
import sys
input=sys.stdin.readline

N,M=map(int,input().split())

inf=float("inf")
length=[[0 if i==j else -inf for j in range(N)] for i in range(N)]

for _ in range(M):
    a,b,c=map(int,input().split())
    length[a-1][b-1]=length[b-1][a-1]=max(length[a-1][b-1],c)

DP=[[-inf]*N for _ in range(1<<N)]
for v in range(N):
    DP[1<<v][v]=0

for S in range(1<<N):
    for v in range(N):
        if (S>>v)&1==0:
            continue

        for w in range(N):
            if (S>>w)&1==1:
                continue

            DP[S|(1<<w)][w]=max(DP[S|(1<<w)][w], DP[S][v]+length[v][w])

Ans=-inf
for S in range(1<<N):
    Ans=max(Ans, max(DP[S]))
print(Ans)
0