結果

問題 No.845 最長の切符
ユーザー pengincoalitionpengincoalition
提出日時 2019-07-05 18:49:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 687 ms / 3,000 ms
コード長 762 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 89,944 KB
最終ジャッジ日時 2023-10-22 01:59:50
合計ジャッジ時間 6,138 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,592 KB
testcase_01 AC 44 ms
55,640 KB
testcase_02 AC 52 ms
64,040 KB
testcase_03 AC 44 ms
53,592 KB
testcase_04 AC 44 ms
53,592 KB
testcase_05 AC 44 ms
53,592 KB
testcase_06 AC 44 ms
53,592 KB
testcase_07 AC 44 ms
53,592 KB
testcase_08 AC 73 ms
70,844 KB
testcase_09 AC 53 ms
62,040 KB
testcase_10 AC 82 ms
76,576 KB
testcase_11 AC 67 ms
70,820 KB
testcase_12 AC 70 ms
73,808 KB
testcase_13 AC 65 ms
68,764 KB
testcase_14 AC 62 ms
68,684 KB
testcase_15 AC 173 ms
79,400 KB
testcase_16 AC 687 ms
89,764 KB
testcase_17 AC 195 ms
79,600 KB
testcase_18 AC 306 ms
82,776 KB
testcase_19 AC 126 ms
77,924 KB
testcase_20 AC 583 ms
89,508 KB
testcase_21 AC 437 ms
89,492 KB
testcase_22 AC 198 ms
79,536 KB
testcase_23 AC 106 ms
77,112 KB
testcase_24 AC 666 ms
89,944 KB
testcase_25 AC 44 ms
53,592 KB
testcase_26 AC 98 ms
85,252 KB
testcase_27 AC 44 ms
53,592 KB
testcase_28 AC 110 ms
85,804 KB
testcase_29 AC 44 ms
53,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import copy

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

x=[[-1 for j in range(N)] for i in range(N)]
for i in range(M):
    temp1,temp2,temp3=tuple(map(int,input("").split(" ")))
    temp1-=1
    temp2-=1
    x[temp1][temp2]=max([temp3,x[temp2][temp1]])
    x[temp2][temp1]=max([temp3,x[temp2][temp1]])


dp_s=[]

if True:
    dp=[[-1 for j in range(N)] for i in range(1<<N)]
    for i in range(N):
        dp[1<<i][i]=0
    A=-100000000000000000
    for i2 in range(0,1<<N):
        for i3 in range(N):
            if  dp[i2][i3]>=0:
                A=max([A,dp[i2][i3]])
                for j in range(N):
                    if x[i3][j]>=0 and not(i2&(1<<j)):
                        dp[i2|(1<<j)][j]=max([dp[i2][i3]+x[i3][j],dp[i2|(1<<j)][j]])
    print(A)




0