結果

問題 No.788 トラックの移動
ユーザー mkawa2mkawa2
提出日時 2021-02-11 18:53:47
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,507 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 114,216 KB
最終ジャッジ日時 2023-09-25 08:36:09
合計ジャッジ時間 12,962 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,826 ms
113,096 KB
testcase_01 AC 68 ms
71,504 KB
testcase_02 AC 68 ms
71,176 KB
testcase_03 AC 67 ms
71,564 KB
testcase_04 AC 550 ms
86,708 KB
testcase_05 TLE -
testcase_06 AC 1,963 ms
113,888 KB
testcase_07 AC 74 ms
71,432 KB
testcase_08 AC 71 ms
71,400 KB
testcase_09 AC 69 ms
71,576 KB
testcase_10 AC 70 ms
71,392 KB
testcase_11 AC 71 ms
71,404 KB
testcase_12 AC 72 ms
71,292 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 575 ms
109,948 KB
testcase_16 AC 1,929 ms
114,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def MI1(): return map(int1, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
inf = 10**16
# md = 998244353
md = 10**9+7

from heapq import *

def dijk(u):
    hp = []
    dist = [inf]*n
    dist[u] = 0
    heappush(hp, (0, u))
    while hp:
        d, u = heappop(hp)
        if dist[u] > d: 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()
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.append(dijk(u))
# p2D(dd)

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

print(ans)
0