結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | Theta |
提出日時 | 2023-01-27 18:24:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,568 ms / 2,000 ms |
コード長 | 1,281 bytes |
コンパイル時間 | 218 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 194,500 KB |
最終ジャッジ日時 | 2024-06-28 03:42:15 |
合計ジャッジ時間 | 35,662 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
52,864 KB |
testcase_01 | AC | 44 ms
53,376 KB |
testcase_02 | AC | 736 ms
134,596 KB |
testcase_03 | AC | 1,321 ms
193,460 KB |
testcase_04 | AC | 1,370 ms
194,500 KB |
testcase_05 | AC | 856 ms
192,136 KB |
testcase_06 | AC | 861 ms
192,264 KB |
testcase_07 | AC | 271 ms
102,848 KB |
testcase_08 | AC | 612 ms
179,392 KB |
testcase_09 | AC | 191 ms
84,920 KB |
testcase_10 | AC | 356 ms
119,512 KB |
testcase_11 | AC | 281 ms
105,764 KB |
testcase_12 | AC | 505 ms
101,204 KB |
testcase_13 | AC | 1,155 ms
152,708 KB |
testcase_14 | AC | 1,201 ms
164,380 KB |
testcase_15 | AC | 1,402 ms
180,976 KB |
testcase_16 | AC | 894 ms
122,484 KB |
testcase_17 | AC | 1,532 ms
186,584 KB |
testcase_18 | AC | 652 ms
107,356 KB |
testcase_19 | AC | 1,324 ms
180,656 KB |
testcase_20 | AC | 427 ms
103,884 KB |
testcase_21 | AC | 890 ms
121,212 KB |
testcase_22 | AC | 1,380 ms
170,860 KB |
testcase_23 | AC | 132 ms
77,312 KB |
testcase_24 | AC | 134 ms
77,696 KB |
testcase_25 | AC | 463 ms
98,688 KB |
testcase_26 | AC | 849 ms
135,228 KB |
testcase_27 | AC | 895 ms
133,152 KB |
testcase_28 | AC | 1,519 ms
174,624 KB |
testcase_29 | AC | 303 ms
87,552 KB |
testcase_30 | AC | 1,568 ms
184,932 KB |
testcase_31 | AC | 964 ms
150,132 KB |
testcase_32 | AC | 757 ms
122,448 KB |
testcase_33 | AC | 1,284 ms
176,132 KB |
testcase_34 | AC | 653 ms
112,832 KB |
testcase_35 | AC | 1,427 ms
182,560 KB |
testcase_36 | AC | 122 ms
76,928 KB |
testcase_37 | AC | 178 ms
78,208 KB |
testcase_38 | AC | 142 ms
77,440 KB |
testcase_39 | AC | 155 ms
78,592 KB |
testcase_40 | AC | 101 ms
76,032 KB |
testcase_41 | AC | 1,174 ms
183,132 KB |
testcase_42 | AC | 438 ms
107,204 KB |
testcase_43 | AC | 670 ms
131,196 KB |
testcase_44 | AC | 320 ms
95,260 KB |
testcase_45 | AC | 687 ms
128,784 KB |
testcase_46 | AC | 43 ms
53,120 KB |
testcase_47 | AC | 45 ms
53,120 KB |
ソースコード
from heapq import heappop, heappush from math import inf, sqrt from operator import ne class Point: def __init__(self, x, y) -> None: self.x = x self.y = y def distance_to(self, __o: object): if not isinstance(__o, Point): raise ValueError return sqrt((self.x - __o.x)**2 + (self.y - __o.y)**2) def main(): N, M = map(int, input().split()) X, Y = map(int, input().split()) X -= 1 Y -= 1 nodes = [Point(*map(int, input().split())) for _ in range(N)] weights = [{} for _ in range(N)] for _ in range(M): start, end = map(int, input().split()) weights[start-1][end-1] = nodes[start-1].distance_to(nodes[end-1]) weights[end-1][start-1] = weights[start-1][end-1] searched = [] heappush(searched, (0, X)) costs = [inf for _ in range(N)] decided = set() while searched: current_cost, next_node_idx = heappop(searched) if next_node_idx in decided: continue costs[next_node_idx] = current_cost decided.add(next_node_idx) for dest_idx, distance in weights[next_node_idx].items(): heappush(searched, (current_cost + distance, dest_idx)) print(costs[Y]) if __name__ == "__main__": main()