結果

問題 No.845 最長の切符
コンテスト
ユーザー pengincoalition
提出日時 2019-07-05 18:49:13
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 762 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 460 ms
コンパイル使用メモリ 20,952 KB
実行使用メモリ 43,992 KB
最終ジャッジ日時 2026-04-10 08:53:42
合計ジャッジ時間 22,113 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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