結果

問題 No.788 トラックの移動
ユーザー mkawa2mkawa2
提出日時 2021-02-11 21:00:13
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,556 bytes
コンパイル時間 1,169 ms
コンパイル使用メモリ 86,732 KB
実行使用メモリ 114,284 KB
最終ジャッジ日時 2023-09-25 10:40:45
合計ジャッジ時間 14,033 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 75 ms
71,496 KB
testcase_02 AC 77 ms
71,160 KB
testcase_03 AC 77 ms
71,512 KB
testcase_04 AC 608 ms
86,640 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 76 ms
71,192 KB
testcase_08 AC 76 ms
71,244 KB
testcase_09 AC 75 ms
71,200 KB
testcase_10 AC 76 ms
71,316 KB
testcase_11 AC 76 ms
71,120 KB
testcase_12 AC 77 ms
71,320 KB
testcase_13 AC 82 ms
71,204 KB
testcase_14 AC 75 ms
71,048 KB
testcase_15 AC 613 ms
110,076 KB
testcase_16 TLE -
権限があれば一括ダウンロードができます

ソースコード

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 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.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