結果
問題 | No.788 トラックの移動 |
ユーザー |
![]() |
提出日時 | 2025-03-31 17:47:31 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,601 bytes |
コンパイル時間 | 266 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 88,520 KB |
最終ジャッジ日時 | 2025-03-31 17:48:57 |
合計ジャッジ時間 | 12,960 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 2 TLE * 2 |
ソースコード
import heapq def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]); idx +=1 M = int(data[idx]); idx +=1 L = int(data[idx]); idx +=1 t = list(map(int, data[idx:idx+N])); idx +=N adj = [[] for _ in range(N+1)] for _ in range(M): a = int(data[idx]); idx +=1 b = int(data[idx]); idx +=1 c = int(data[idx]); idx +=1 adj[a].append((b, c)) adj[b].append((a, c)) def dijkstra(start, n): dist = [float('inf')] * (n+1) dist[start] = 0 heap = [] heapq.heappush(heap, (0, start)) while heap: current_dist, u = heapq.heappop(heap) if current_dist > dist[u]: continue for v, w in adj[u]: if dist[v] > dist[u] + w: dist[v] = dist[u] + w heapq.heappush(heap, (dist[v], v)) return dist d_L = dijkstra(L, N) global_min = float('inf') for X in range(1, N+1): d_x = dijkstra(X, N) sum_part = 0 for i in range(1, N+1): if t[i-1] > 0: sum_part += 2 * d_x[i] * t[i-1] min_candidate = float('inf') for i in range(1, N+1): if t[i-1] > 0: current = d_L[i] - d_x[i] if current < min_candidate: min_candidate = current total = sum_part + min_candidate if total < global_min: global_min = total print(global_min) if __name__ == "__main__": main()