結果

問題 No.788 トラックの移動
ユーザー mkawa2mkawa2
提出日時 2021-02-12 00:07:57
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,025 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 259,912 KB
最終ジャッジ日時 2023-09-25 13:55:44
合計ジャッジ時間 14,436 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 86 ms
71,624 KB
testcase_02 AC 80 ms
71,424 KB
testcase_03 AC 77 ms
71,432 KB
testcase_04 AC 640 ms
146,548 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 79 ms
71,400 KB
testcase_08 AC 81 ms
71,356 KB
testcase_09 AC 77 ms
71,360 KB
testcase_10 AC 78 ms
71,148 KB
testcase_11 AC 80 ms
71,160 KB
testcase_12 AC 79 ms
71,408 KB
testcase_13 AC 79 ms
71,512 KB
testcase_14 AC 78 ms
71,364 KB
testcase_15 AC 654 ms
256,096 KB
testcase_16 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def MI(): return map(int, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
inf = 10**16

from heapq import *

def dijk(u):
    hp = []
    dist = [inf]*n
    dist[u] = 0
    heappush(hp, (0, u))
    while hp:
        d, u = heappop(hp)
        if d > dist[u]: continue
        for v, c in to[u]:
            nd = d+c
            if nd >= dist[v]: continue
            dist[v] = nd
            heappush(hp, (nd, v))
    return dist

n, m, l = MI()
l -= 1
tt = LI()

if tt.count(0) >= n-1:
    print(0)
    exit()

to = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = MI()
    a, b = a-1, b-1
    to[a].append((b, c))
    to[b].append((a, c))

dd = []
for u in range(n):
    dd+=dijk(u)
# print(dd)

ans = inf
for g in range(n):
    mn = inf
    for s in range(n):
        if tt[s] == 0: continue
        cur = dd[l*n+s]-dd[s*n+g]
        if cur < mn: mn = cur
    mn += sum(tt[u]*dd[u*n+g] for u in range(n))*2
    if mn < ans: ans = mn

print(ans)
0