結果

問題 No.788 トラックの移動
ユーザー convexineqconvexineq
提出日時 2021-03-25 06:52:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,011 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 82,444 KB
最終ジャッジ日時 2024-05-05 07:40:22
合計ジャッジ時間 10,030 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,551 ms
82,196 KB
testcase_01 AC 42 ms
52,352 KB
testcase_02 AC 43 ms
52,480 KB
testcase_03 AC 44 ms
52,608 KB
testcase_04 AC 459 ms
76,656 KB
testcase_05 AC 1,558 ms
82,444 KB
testcase_06 AC 1,621 ms
82,320 KB
testcase_07 AC 38 ms
52,480 KB
testcase_08 AC 38 ms
52,224 KB
testcase_09 AC 38 ms
52,096 KB
testcase_10 AC 38 ms
52,608 KB
testcase_11 AC 39 ms
53,248 KB
testcase_12 AC 39 ms
52,224 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 441 ms
76,872 KB
testcase_16 AC 1,308 ms
80,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
def dijkstra(g,start):
    n = len(g)
    M = 1<<32
    INF = 1<<60
    dist = [INF]*n #startからの最短距離
    dist[start] = 0
    q = [start] #(そこまでの距離、点)
    while q:
        dv,v = divmod(heappop(q),M)
        if dist[v] < dv: continue
        for to, cost in g[v]:
            if dv + cost < dist[to]:
                dist[to] = dv + cost
                heappush(q, (dist[to]*M+to))
    return dist

def solve(x):
    dist = dijkstra(g,x)
    res = 0
    direct = 1<<60
    for i in range(n):
        if t[i] == 0: continue
        res += t[i]*2*dist[i]
        direct = min(direct,dL[i] - dist[i])
    return res+direct

import sys
input = sys.stdin.readline

n,m,L = map(int,input().split())
L -= 1
*t, = map(int,input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    g[a-1].append((b-1, c))
    g[b-1].append((a-1, c))
dL = dijkstra(g,L)
ans = 10**18
for i in range(n):
    ans = min(ans,solve(i))
print(ans)
0