結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー stngstng
提出日時 2022-08-19 17:28:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,211 ms / 2,000 ms
コード長 1,110 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 170,688 KB
最終ジャッジ日時 2024-04-16 21:13:58
合計ジャッジ時間 29,892 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
52,736 KB
testcase_01 AC 44 ms
53,120 KB
testcase_02 AC 665 ms
123,660 KB
testcase_03 AC 909 ms
170,688 KB
testcase_04 AC 842 ms
170,440 KB
testcase_05 AC 651 ms
170,164 KB
testcase_06 AC 651 ms
169,768 KB
testcase_07 AC 231 ms
100,864 KB
testcase_08 AC 600 ms
168,576 KB
testcase_09 AC 143 ms
81,024 KB
testcase_10 AC 336 ms
118,144 KB
testcase_11 AC 266 ms
104,704 KB
testcase_12 AC 251 ms
103,424 KB
testcase_13 AC 845 ms
142,120 KB
testcase_14 AC 928 ms
149,068 KB
testcase_15 AC 966 ms
159,244 KB
testcase_16 AC 569 ms
122,224 KB
testcase_17 AC 1,157 ms
168,452 KB
testcase_18 AC 451 ms
110,532 KB
testcase_19 AC 1,073 ms
160,816 KB
testcase_20 AC 363 ms
101,244 KB
testcase_21 AC 470 ms
119,528 KB
testcase_22 AC 1,001 ms
153,904 KB
testcase_23 AC 87 ms
77,184 KB
testcase_24 AC 103 ms
77,056 KB
testcase_25 AC 233 ms
98,304 KB
testcase_26 AC 615 ms
124,108 KB
testcase_27 AC 661 ms
126,820 KB
testcase_28 AC 1,043 ms
158,148 KB
testcase_29 AC 227 ms
89,472 KB
testcase_30 AC 1,062 ms
159,184 KB
testcase_31 AC 705 ms
135,216 KB
testcase_32 AC 536 ms
116,336 KB
testcase_33 AC 1,110 ms
159,144 KB
testcase_34 AC 468 ms
111,360 KB
testcase_35 AC 1,053 ms
162,464 KB
testcase_36 AC 99 ms
77,184 KB
testcase_37 AC 158 ms
78,720 KB
testcase_38 AC 119 ms
77,440 KB
testcase_39 AC 159 ms
78,848 KB
testcase_40 AC 75 ms
67,584 KB
testcase_41 AC 1,211 ms
169,600 KB
testcase_42 AC 448 ms
105,728 KB
testcase_43 AC 683 ms
125,768 KB
testcase_44 AC 320 ms
95,232 KB
testcase_45 AC 663 ms
124,672 KB
testcase_46 AC 43 ms
52,608 KB
testcase_47 AC 43 ms
52,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
INF = 10 ** 9
def dijkstra(s, n): # (始点, ノード数)
    dist = [INF] * n
    hq = [(0, s)] # (distance, node)
    dist[s] = 0
    seen = [False] * n # ノードが確定済みかどうか
    while hq:
        tmp = heappop(hq) # ノードを pop する
        v = tmp[1]
        c = tmp[0]
        seen[v] = True
        if dist[v] != c:
            continue
        for to, cost in adj[v]: # ノード v に隣接しているノードに対して
            if seen[to] == False and dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(hq, (dist[to], to))
    return dist

n,m = map(int,input().split())
x,y = map(int,input().split())
pq = [[int(i) for i in input().split()] for j in range(n)]
PQ = [[int(i) for i in input().split()] for j in range(m)]

adj = [[] for i in range(n)]

for i in range(m):
    P,Q = PQ[i]
    P -= 1
    Q -= 1
    lp = pq[P]
    lq = pq[Q]
    tmp = ((lp[0]-lq[0])**2+(lp[1]-lq[1])**2)**0.5
    adj[P].append([Q,tmp])
    adj[Q].append([P,tmp])

x -= 1
y -= 1
di = dijkstra(x,n)
print(di[y])
0