結果
問題 | No.2764 Warp Drive Spacecraft |
ユーザー | lydialitvyak |
提出日時 | 2024-06-10 10:27:31 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,584 bytes |
コンパイル時間 | 191 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 118,152 KB |
最終ジャッジ日時 | 2024-06-10 10:27:40 |
合計ジャッジ時間 | 8,995 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
16,256 KB |
testcase_01 | AC | 30 ms
10,880 KB |
testcase_02 | AC | 32 ms
10,880 KB |
testcase_03 | WA | - |
testcase_04 | AC | 30 ms
10,880 KB |
testcase_05 | AC | 31 ms
11,008 KB |
testcase_06 | AC | 31 ms
10,880 KB |
testcase_07 | AC | 31 ms
10,880 KB |
testcase_08 | AC | 33 ms
11,008 KB |
testcase_09 | AC | 31 ms
10,880 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 31 ms
10,880 KB |
testcase_15 | AC | 32 ms
10,880 KB |
testcase_16 | TLE | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
ソースコード
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)