結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | Coki628 |
提出日時 | 2020-10-27 00:13:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 982 ms / 2,000 ms |
コード長 | 1,612 bytes |
コンパイル時間 | 346 ms |
コンパイル使用メモリ | 82,844 KB |
実行使用メモリ | 135,788 KB |
最終ジャッジ日時 | 2024-07-21 21:46:52 |
合計ジャッジ時間 | 24,951 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
54,364 KB |
testcase_01 | AC | 41 ms
54,136 KB |
testcase_02 | AC | 516 ms
105,660 KB |
testcase_03 | AC | 694 ms
135,788 KB |
testcase_04 | AC | 694 ms
135,168 KB |
testcase_05 | AC | 495 ms
131,224 KB |
testcase_06 | AC | 511 ms
131,072 KB |
testcase_07 | AC | 171 ms
90,624 KB |
testcase_08 | AC | 413 ms
130,492 KB |
testcase_09 | AC | 98 ms
78,584 KB |
testcase_10 | AC | 221 ms
99,148 KB |
testcase_11 | AC | 181 ms
91,504 KB |
testcase_12 | AC | 185 ms
88,712 KB |
testcase_13 | AC | 688 ms
115,384 KB |
testcase_14 | AC | 764 ms
122,272 KB |
testcase_15 | AC | 859 ms
129,648 KB |
testcase_16 | AC | 494 ms
102,336 KB |
testcase_17 | AC | 974 ms
135,168 KB |
testcase_18 | AC | 393 ms
94,836 KB |
testcase_19 | AC | 890 ms
131,072 KB |
testcase_20 | AC | 301 ms
90,880 KB |
testcase_21 | AC | 455 ms
99,528 KB |
testcase_22 | AC | 839 ms
124,928 KB |
testcase_23 | AC | 62 ms
68,352 KB |
testcase_24 | AC | 67 ms
70,912 KB |
testcase_25 | AC | 169 ms
85,156 KB |
testcase_26 | AC | 481 ms
105,284 KB |
testcase_27 | AC | 562 ms
106,084 KB |
testcase_28 | AC | 902 ms
126,976 KB |
testcase_29 | AC | 202 ms
84,224 KB |
testcase_30 | AC | 865 ms
129,772 KB |
testcase_31 | AC | 589 ms
113,612 KB |
testcase_32 | AC | 441 ms
100,648 KB |
testcase_33 | AC | 946 ms
131,276 KB |
testcase_34 | AC | 408 ms
95,864 KB |
testcase_35 | AC | 871 ms
131,456 KB |
testcase_36 | AC | 69 ms
72,544 KB |
testcase_37 | AC | 109 ms
77,452 KB |
testcase_38 | AC | 75 ms
74,248 KB |
testcase_39 | AC | 106 ms
78,080 KB |
testcase_40 | AC | 54 ms
62,976 KB |
testcase_41 | AC | 982 ms
131,892 KB |
testcase_42 | AC | 339 ms
93,824 KB |
testcase_43 | AC | 537 ms
106,240 KB |
testcase_44 | AC | 249 ms
87,808 KB |
testcase_45 | AC | 518 ms
105,472 KB |
testcase_46 | AC | 41 ms
53,760 KB |
testcase_47 | AC | 41 ms
53,376 KB |
ソースコード
import sys from math import hypot def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)] def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF = 10**19 MOD = 10**9 + 7 EPS = 10**-10 def dijkstra(nodes: list, src: int) -> list: """ ダイクストラ(隣接リスト(0-indexed), 始点) """ from heapq import heappush, heappop N = len(nodes) res = [INF] * N que = [(0, src)] res[src] = 0 while que: dist, cur = heappop(que) if res[cur] < dist: continue for nxt, cost in nodes[cur]: if dist + cost < res[nxt]: res[nxt] = dist + cost heappush(que, (dist+cost, nxt)) return res N, M = MAP() s, t = MAP() s -= 1; t -= 1 def calc(a, b): return hypot(XY[a][0]-XY[b][0], XY[a][1]-XY[b][1]) XY = [] for i in range(N): x, y = MAP() XY.append((x, y)) nodes = [[] for i in range(N)] for i in range(M): a, b = MAP() a -= 1; b -= 1 c = calc(a, b) nodes[a].append((b, c)) nodes[b].append((a, c)) ans = dijkstra(nodes, s)[t] print(ans)