結果
問題 | 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 sysimport heapqdef read_input():input = sys.stdin.readdata = input().split()index = 0N = int(data[index])M = int(data[index + 1])index += 2W = list(map(int, data[index: index + N]))index += Nedges = []for _ in range(M):U = int(data[index]) - 1V = int(data[index + 1]) - 1T = int(data[index + 2])edges.append((U, V, T))index += 3return N, M, W, edgesdef 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 graphdef dijkstra(N, graph, W):dist = [float("inf")] * Ndist[0] = 0pq = [(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 + timeif new_dist < dist[v]:dist[v] = new_distheapq.heappush(pq, (new_dist, v))# ワープ移動for v in range(N):if v != u:warp_time = W[u] * W[v]new_dist = current_dist + warp_timeif new_dist < dist[v]:dist[v] = new_distheapq.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)