結果

問題 No.788 トラックの移動
ユーザー brthyyjpbrthyyjp
提出日時 2022-01-13 08:52:08
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,147 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 114,184 KB
最終ジャッジ日時 2023-08-21 17:40:43
合計ジャッジ時間 13,455 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 75 ms
71,380 KB
testcase_02 AC 74 ms
71,540 KB
testcase_03 AC 76 ms
71,492 KB
testcase_04 AC 569 ms
86,332 KB
testcase_05 AC 1,993 ms
113,120 KB
testcase_06 TLE -
testcase_07 AC 76 ms
71,624 KB
testcase_08 AC 77 ms
71,584 KB
testcase_09 AC 74 ms
71,536 KB
testcase_10 AC 74 ms
71,624 KB
testcase_11 AC 76 ms
71,464 KB
testcase_12 AC 75 ms
71,320 KB
testcase_13 AC 74 ms
71,132 KB
testcase_14 AC 74 ms
71,404 KB
testcase_15 AC 583 ms
111,524 KB
testcase_16 AC 1,937 ms
113,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
INF = 1<<60
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

def main():

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

    D = [dijkstra(i, g) for i in range(n)]

    ans = INF
    for i in range(n):
        s=sum(T[j]*D[i][j] for j in range(n))*2
        if s:
            s+=min(D[l][j]-D[i][j] for j in range(n) if T[j])
        ans=min(ans,s)
    print(ans)

if __name__ == '__main__':
    main()
0