結果

問題 No.788 トラックの移動
ユーザー SSlimeSSlime
提出日時 2020-06-17 15:59:15
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 1,040 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 18,128 KB
最終ジャッジ日時 2023-09-16 11:29:51
合計ジャッジ時間 6,541 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
n,m,l = map(int,input().split())
l -= 1
T = list(map(int,input().split()))
from heapq import *
def Dijkstra(n,path,start):
    inf = float('inf')
    d = [inf]*n
    d[start] = 0
    pq = [(0, start)]
    heapify(pq)
    while pq:
        dist, p = heappop(pq)
        if dist > d[p]:continue
        for nxt,cost in path[p].items():
            if dist + cost >= d[nxt]:continue
            d[nxt] = dist + cost
            heappush(pq,(d[nxt],nxt))
    return d
path = [{} for _ in range(n)]
for i in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    path[a][b] = c
    path[b][a] = c

ld = Dijkstra(n,path,l)
def total(n,path,t,start,ld):
    d = Dijkstra(n,path,start)
    res = 0
    delta = float('inf')
    for i in range(n):
        res += 2*d[i]*t[i]
        if t[i] > 0:
            delta = min(delta, ld[i] - d[i])
    if res == 0:return res
    else:
        return res + delta
ans = float('inf')
for i in range(n):
    ans = min(ans,total(n,path,T,i,ld))
print(ans)
0