結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-05 17:51:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,114 ms / 2,000 ms |
| コード長 | 1,308 bytes |
| コンパイル時間 | 230 ms |
| コンパイル使用メモリ | 82,196 KB |
| 実行使用メモリ | 142,820 KB |
| 最終ジャッジ日時 | 2024-11-20 18:46:05 |
| 合計ジャッジ時間 | 27,372 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
def I():return int(input())
def MAP():return map(int,input().split())
def MAPs():return map(str,input().split())
def LI(): return list(map(int,input().split()))
def TPL(): return tuple(map(int,input().split()))
def S():return input()
from collections import defaultdict,Counter,deque
from copy import deepcopy
from heapq import heapify,heappop,heappush
from bisect import bisect_left,bisect_right
from itertools import accumulate,product,permutations,combinations
from math import gcd,ceil,floor,sqrt
inf=float('inf')
n,m=MAP()
start,goal=MAP()
point=[TPL() for _ in range(n)]
g=[[] for _ in range(n)]
for _ in range(m):
p,q=MAP()
x,y=point[p-1];X,Y=point[q-1]
d=(x-X)**2+(y-Y)**2
d=sqrt(d)
g[p-1].append((q-1,d))
g[q-1].append((p-1,d))
def dijkstra(start):
dst=[10**18]*n
visit=[False]*n
q=[]
heappush(q,(0,start))
while q:
now_cost,now_place=heappop(q)
if visit[now_place]:
continue
visit[now_place]=True
dst[now_place]=now_cost
for to_place,cost in g[now_place]:
if visit[to_place]:
continue
if dst[to_place]>now_cost+cost:
dst[to_place]=now_cost+cost
heappush(q,(dst[to_place],to_place))
return dst
print(dijkstra(start-1)[goal-1])