結果

問題 No.788 トラックの移動
ユーザー SSlimeSSlime
提出日時 2020-06-17 15:54:36
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,002 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 86,772 KB
実行使用メモリ 87,556 KB
最終ジャッジ日時 2023-09-16 11:29:33
合計ジャッジ時間 14,169 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,995 ms
86,816 KB
testcase_01 AC 76 ms
71,352 KB
testcase_02 AC 77 ms
71,304 KB
testcase_03 AC 76 ms
71,552 KB
testcase_04 AC 597 ms
80,428 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 73 ms
71,384 KB
testcase_08 WA -
testcase_09 AC 76 ms
71,180 KB
testcase_10 AC 75 ms
71,300 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 74 ms
71,544 KB
testcase_14 AC 75 ms
71,304 KB
testcase_15 AC 569 ms
79,636 KB
testcase_16 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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