結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー wolgnikwolgnik
提出日時 2020-05-29 21:55:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 804 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 143,096 KB
最終ジャッジ日時 2024-04-23 21:56:21
合計ジャッジ時間 19,874 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,864 KB
testcase_01 AC 41 ms
53,120 KB
testcase_02 AC 385 ms
106,404 KB
testcase_03 AC 654 ms
142,124 KB
testcase_04 AC 617 ms
143,096 KB
testcase_05 AC 473 ms
142,604 KB
testcase_06 AC 457 ms
142,224 KB
testcase_07 AC 123 ms
90,840 KB
testcase_08 AC 262 ms
134,356 KB
testcase_09 AC 84 ms
78,464 KB
testcase_10 AC 157 ms
102,208 KB
testcase_11 AC 128 ms
90,652 KB
testcase_12 AC 266 ms
95,232 KB
testcase_13 AC 638 ms
121,748 KB
testcase_14 AC 670 ms
126,556 KB
testcase_15 AC 741 ms
132,792 KB
testcase_16 AC 478 ms
107,068 KB
testcase_17 AC 804 ms
139,360 KB
testcase_18 AC 373 ms
100,244 KB
testcase_19 AC 727 ms
133,672 KB
testcase_20 AC 274 ms
91,756 KB
testcase_21 AC 471 ms
107,296 KB
testcase_22 AC 705 ms
129,192 KB
testcase_23 AC 101 ms
77,476 KB
testcase_24 AC 104 ms
77,568 KB
testcase_25 AC 246 ms
93,292 KB
testcase_26 AC 441 ms
108,420 KB
testcase_27 AC 497 ms
110,536 KB
testcase_28 AC 746 ms
133,584 KB
testcase_29 AC 201 ms
85,460 KB
testcase_30 AC 749 ms
133,924 KB
testcase_31 AC 518 ms
117,108 KB
testcase_32 AC 385 ms
103,496 KB
testcase_33 AC 704 ms
132,884 KB
testcase_34 AC 387 ms
100,288 KB
testcase_35 AC 765 ms
136,204 KB
testcase_36 AC 101 ms
77,156 KB
testcase_37 AC 114 ms
77,840 KB
testcase_38 AC 97 ms
77,380 KB
testcase_39 AC 111 ms
77,200 KB
testcase_40 AC 70 ms
69,760 KB
testcase_41 AC 702 ms
134,296 KB
testcase_42 AC 257 ms
94,672 KB
testcase_43 AC 389 ms
106,680 KB
testcase_44 AC 190 ms
88,320 KB
testcase_45 AC 374 ms
106,268 KB
testcase_46 AC 38 ms
53,248 KB
testcase_47 AC 38 ms
53,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from math import sqrt
input = sys.stdin.readline
N, M = map(int, input().split())
X, Y = map(int, input().split())
e = [[] for _ in range(N + 1)]
ps = [(0, 0)]
for _ in range(N):
  p, q = map(int, input().split())
  ps.append((p, q))
for _ in range(M):
  p, q = map(int, input().split())
  e[p].append((q, sqrt((ps[p][0] - ps[q][0]) ** 2 + (ps[p][1] - ps[q][1]) ** 2)))
  e[q].append((p, sqrt((ps[p][0] - ps[q][0]) ** 2 + (ps[p][1] - ps[q][1]) ** 2)))
import heapq
hpush = heapq.heappush
hpop = heapq.heappop
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s):
    d = [float("inf")] * (self.n + 1)
    vis = [0] * (self.n + 1)
    d[s] = 0
    h = [(0, s)]
    while len(h):
      v0, v1 = hpop(h)
      if vis[v1]: continue
      vis[v1] = 1
      for p in self.e[v1]:
        d[p[0]] = min(d[p[0]], d[v1] + p[1])
        if vis[p[0]]: continue
        hpush(h, (d[p[0]], p[0]))
    return d
dij = dijkstra(N, e)
print(dij.path(X)[Y])
0