結果

問題 No.807 umg tours
ユーザー tomarint2tomarint2
提出日時 2019-03-22 22:27:24
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 865 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 81,628 KB
実行使用メモリ 97,176 KB
最終ジャッジ日時 2023-10-19 09:45:17
合計ジャッジ時間 11,135 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import copy

N,M=map(int,input().split())
d=[[0 for j in range(N+1)] for i in range(N+1)]
for i in range(M):
    a,b,c=map(int,input().split())
    d[a][b]=d[b][a]=c
inf=1<<60

#現在地、ゴール、コスト、チケット利用回数、履歴
def solve(location, goal, cost, ticket, history):
    cost2 = inf
    #print('solve', location, goal, cost, ticket)
    history2 = copy.copy(history)
    history2.add(location)
    if location==goal:
        return cost
    for i in range(1,N+1):
        if d[location][i]==0:
            continue
        if i in history2:
            continue
        cost2=min(cost2,solve(i,goal,cost+d[location][i],ticket,history2))
        if ticket==0:
            cost2=min(cost2,solve(i,goal,cost,1,history2))
    return cost2

for i in range(1,N+1):
    ans=solve(1, i, 0, 0, set()) + solve(1, i, 0, 1, set())
    print(ans)
0