結果

問題 No.788 トラックの移動
ユーザー vwxyzvwxyz
提出日時 2022-09-27 16:15:56
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,435 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 113,916 KB
最終ジャッジ日時 2023-08-24 03:55:23
合計ジャッジ時間 14,934 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 76 ms
71,344 KB
testcase_02 AC 74 ms
71,496 KB
testcase_03 AC 75 ms
71,196 KB
testcase_04 AC 588 ms
86,860 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 76 ms
71,300 KB
testcase_08 AC 75 ms
71,296 KB
testcase_09 AC 75 ms
71,324 KB
testcase_10 AC 76 ms
71,248 KB
testcase_11 AC 78 ms
71,464 KB
testcase_12 AC 77 ms
71,312 KB
testcase_13 AC 77 ms
71,200 KB
testcase_14 AC 77 ms
71,200 KB
testcase_15 AC 580 ms
110,428 KB
testcase_16 AC 1,999 ms
113,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline
import heapq

class Graph:
    def __init__(self,V,edges=False,graph=False,directed=False,weighted=False,inf=float("inf")):
        self.V=V
        self.directed=directed
        self.weighted=weighted
        self.inf=inf
        self.graph=graph

    def Dijkstra(self,s,route_restoration=False):
        dist=[self.inf]*self.V
        dist[s]=0
        hq=[(0,s)]
        if route_restoration:
            parents=[None]*self.V
        while hq:
            dx,x=heapq.heappop(hq)
            if dist[x]<dx:
                continue
            for y,dy in self.graph[x]:
                if dist[y]>dx+dy:
                    dist[y]=dx+dy
                    if route_restoration:
                        parents[y]=x
                    heapq.heappush(hq,(dist[y],y))
        if route_restoration:
            return dist,parents
        else:
            return dist

N,M,L=map(int,readline().split())
L-=1
T=list(map(int,readline().split()))
graph=[[] for i in range(N)]
for _ in range(M):
    a,b,c=map(int,readline().split())
    a-=1;b-=1
    graph[a].append((b,c))
    graph[b].append((a,c))
inf=1<<60
G=Graph(N,graph=graph,weighted=True,inf=inf)
dist=[G.Dijkstra(i) for i in range(N)]
ans=inf
idx=[j for j in range(N) if T[j]]
for i in range(N):
    s=sum(T[j]*dist[i][j] for j in range(N))*2
    if s:
        s+=min(dist[L][j]-dist[i][j] for j in idx)
    ans=min(ans,s)
print(ans)
0