結果

問題 No.788 トラックの移動
ユーザー kohei2019kohei2019
提出日時 2022-07-29 00:04:07
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,539 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 98,000 KB
最終ジャッジ日時 2023-09-25 18:30:24
合計ジャッジ時間 13,428 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 79 ms
71,088 KB
testcase_02 AC 76 ms
71,444 KB
testcase_03 AC 77 ms
71,344 KB
testcase_04 AC 595 ms
80,624 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 80 ms
71,412 KB
testcase_08 AC 77 ms
71,224 KB
testcase_09 AC 78 ms
71,332 KB
testcase_10 AC 78 ms
71,256 KB
testcase_11 AC 77 ms
71,388 KB
testcase_12 AC 78 ms
71,288 KB
testcase_13 AC 79 ms
71,220 KB
testcase_14 AC 78 ms
71,112 KB
testcase_15 AC 538 ms
79,736 KB
testcase_16 AC 1,999 ms
89,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
def main():
    N,M,L = map(int,input().split())
    L -= 1
    lst = list(map(int,input().split()))
    lsg = [[] for i in range(N)]
    for i in range(M):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        lsg[a].append((b,c))
        lsg[b].append((a,c))
    if sum(lst) == 1:
        print(0)
        exit()
    INF = float('INF')
    distL = [INF]*(N)
    used = [False]*(N)
    distL[L] = 0
    h = [(0,L)]
    while h:
        c,x = heapq.heappop(h)
        if used[x]:
            continue
        used[x] = True
        for j,cos in lsg[x]:
            if used[j]:
                continue
            if distL[j] > distL[x]+cos:
                distL[j] = distL[x]+cos
                heapq.heappush(h, (distL[j],j))
    ans = INF
    for i in range(N):
        st = i
        distC = [INF]*(N)
        used = [False]*(N)
        distC[st] = 0
        h = [(0,st)]
        while h:
            c,x = heapq.heappop(h)
            if used[x]:
                continue
            used[x] = True
            for j,cos in lsg[x]:
                if used[j]:
                    continue
                if distC[j] > distC[x]+cos:
                    distC[j] = distC[x]+cos
                    heapq.heappush(h, (distC[j],j))
        divmax = -INF
        sumcost = 0
        for k in range(N):
            sumcost += distC[k]*lst[k]*2
            if lst[k] >= 1:
                divmax = max(divmax,distC[k]-distL[k])
        ans = min(ans,sumcost-divmax)
    print(ans)
main()
            
0