結果
| 問題 | No.788 トラックの移動 |
| コンテスト | |
| ユーザー |
vwxyz
|
| 提出日時 | 2022-03-24 04:49:44 |
| 言語 | Python3 (3.14.2 + numpy 2.4.0 + scipy 1.16.3) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,435 bytes |
| 記録 | |
| コンパイル時間 | 217 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 126,024 KB |
| 最終ジャッジ日時 | 2024-10-12 09:49:32 |
| 合計ジャッジ時間 | 6,682 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 13 |
ソースコード
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)
vwxyz