結果
問題 |
No.2764 Warp Drive Spacecraft
|
ユーザー |
|
提出日時 | 2024-06-10 10:27:31 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,584 bytes |
コンパイル時間 | 370 ms |
コンパイル使用メモリ | 12,288 KB |
実行使用メモリ | 335,612 KB |
最終ジャッジ日時 | 2025-01-01 21:31:21 |
合計ジャッジ時間 | 99,555 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 8 WA * 4 TLE * 23 |
ソースコード
import sys import heapq def read_input(): input = sys.stdin.read data = input().split() index = 0 N = int(data[index]) M = int(data[index + 1]) index += 2 W = list(map(int, data[index: index + N])) index += N edges = [] for _ in range(M): U = int(data[index]) - 1 V = int(data[index + 1]) - 1 T = int(data[index + 2]) edges.append((U, V, T)) index += 3 return N, M, W, edges def build_graph(N, edges): graph = [[] for _ in range(N)] for U, V, T in edges: graph[U].append((V, T)) graph[V].append((U, T)) return graph def dijkstra(N, graph, W): dist = [float("inf")] * N dist[0] = 0 pq = [(0, 0)] # (distance, node) while pq: current_dist, u = heapq.heappop(pq) if current_dist > dist[u]: continue # 航路に沿った移動 for v, time in graph[u]: new_dist = current_dist + time if new_dist < dist[v]: dist[v] = new_dist heapq.heappush(pq, (new_dist, v)) # ワープ移動 for v in range(N): if v != u: warp_time = W[u] * W[v] new_dist = current_dist + warp_time if new_dist < dist[v]: dist[v] = new_dist heapq.heappush(pq, (new_dist, v)) return dist[N - 1] if __name__ == "__main__": N, M, W, edges = read_input() graph = build_graph(N, edges) shortest_time = dijkstra(N, graph, W) print(shortest_time)