結果

問題 No.788 トラックの移動
ユーザー brthyyjpbrthyyjp
提出日時 2021-09-16 14:15:01
言語 PyPy3
(7.3.13)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,185 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 90,128 KB
最終ジャッジ日時 2023-08-21 17:39:22
合計ジャッジ時間 13,938 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 75 ms
71,160 KB
testcase_02 AC 76 ms
71,588 KB
testcase_03 AC 77 ms
71,384 KB
testcase_04 AC 567 ms
80,144 KB
testcase_05 AC 1,931 ms
88,740 KB
testcase_06 AC 1,898 ms
88,532 KB
testcase_07 AC 76 ms
71,244 KB
testcase_08 AC 74 ms
71,440 KB
testcase_09 AC 74 ms
71,364 KB
testcase_10 AC 73 ms
71,376 KB
testcase_11 AC 77 ms
71,436 KB
testcase_12 AC 75 ms
71,060 KB
testcase_13 AC 75 ms
71,364 KB
testcase_14 AC 74 ms
71,504 KB
testcase_15 AC 447 ms
79,140 KB
testcase_16 AC 1,881 ms
88,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
INF = 10**18
def dijkstra(s, edge):
    n = len(edge)
    dist = [INF]*n
    dist[s] = 0
    edgelist = []
    heapq.heappush(edgelist,(dist[s], s))
    while edgelist:
        minedge = heapq.heappop(edgelist)
        if dist[minedge[1]] < minedge[0]:
            continue
        v = minedge[1]
        for e in edge[v]:
            if dist[e[1]] > dist[v]+e[0]:
                dist[e[1]] = dist[v]+e[0]
                heapq.heappush(edgelist,(dist[e[1]], e[1]))
    return dist

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, m, l = map(int, input().split())
l -= 1
T = list(map(int, input().split()))
g = [[] for i in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    g[a].append((c, b))
    g[b].append((c, a))

cnt = 0
for i in range(n):
    if T[i] != 0:
        cnt += 1
if cnt == 1:
    print(0)
    exit()

d1 = dijkstra(l, g)

ans = INF
for i in range(n):
    d2 = dijkstra(i, g)
    s = 0
    for j in range(n):
        s += d2[j]*T[j]
    for j in range(n):
        if T[j] == 0:
            continue
        temp = 2*s+d1[j]-d2[j]
        ans = min(ans, temp)
print(ans)
0