結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー ronpooronpoo
提出日時 2023-09-07 10:44:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,177 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 162,632 KB
最終ジャッジ日時 2023-09-07 10:45:29
合計ジャッジ時間 34,127 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,716 KB
testcase_01 AC 82 ms
71,416 KB
testcase_02 AC 706 ms
121,264 KB
testcase_03 AC 1,080 ms
160,980 KB
testcase_04 AC 928 ms
160,560 KB
testcase_05 AC 657 ms
161,224 KB
testcase_06 AC 638 ms
161,028 KB
testcase_07 AC 252 ms
92,972 KB
testcase_08 AC 586 ms
159,544 KB
testcase_09 AC 177 ms
82,452 KB
testcase_10 AC 324 ms
103,376 KB
testcase_11 AC 257 ms
96,412 KB
testcase_12 AC 270 ms
97,952 KB
testcase_13 AC 855 ms
135,292 KB
testcase_14 AC 930 ms
141,564 KB
testcase_15 AC 1,000 ms
151,848 KB
testcase_16 AC 607 ms
118,084 KB
testcase_17 AC 1,081 ms
157,484 KB
testcase_18 AC 477 ms
106,352 KB
testcase_19 AC 1,007 ms
152,728 KB
testcase_20 AC 375 ms
98,696 KB
testcase_21 AC 543 ms
113,664 KB
testcase_22 AC 994 ms
145,864 KB
testcase_23 AC 120 ms
78,128 KB
testcase_24 AC 133 ms
78,264 KB
testcase_25 AC 241 ms
91,232 KB
testcase_26 AC 635 ms
120,456 KB
testcase_27 AC 668 ms
122,360 KB
testcase_28 AC 1,042 ms
148,068 KB
testcase_29 AC 272 ms
89,064 KB
testcase_30 AC 1,106 ms
150,212 KB
testcase_31 AC 752 ms
130,744 KB
testcase_32 AC 527 ms
113,104 KB
testcase_33 AC 1,128 ms
150,612 KB
testcase_34 AC 477 ms
107,008 KB
testcase_35 AC 980 ms
152,888 KB
testcase_36 AC 137 ms
79,204 KB
testcase_37 AC 184 ms
79,424 KB
testcase_38 AC 144 ms
78,860 KB
testcase_39 AC 181 ms
79,596 KB
testcase_40 AC 104 ms
76,576 KB
testcase_41 AC 1,177 ms
162,632 KB
testcase_42 AC 433 ms
104,796 KB
testcase_43 AC 675 ms
122,544 KB
testcase_44 AC 329 ms
95,096 KB
testcase_45 AC 687 ms
122,216 KB
testcase_46 AC 81 ms
71,340 KB
testcase_47 AC 85 ms
71,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush

N, M = map(int, input().split())
X, Y = map(int, input().split())
pq = [list(map(int, input().split())) for _ in range(N)]
PQ = [list(map(int, input().split())) for _ in range(M)]

G = [[] for _ in range(N)]
for i in range(M):
    a, b = PQ[i]
    a -= 1
    b -= 1
    d = ((pq[a][0]-pq[b][0])**2 + (pq[a][1]-pq[b][1])**2)**0.5
    G[a].append((b, d))
    G[b].append((a, d))

dist = [float('inf')] * N
dist[X-1] = 0

# dijkstra
def dijkstra(s, g):
    que = []
    heappush(que, (0, s))
    while que:
        cost, now = heappop(que)
        if dist[now] < cost:
            continue
        for nxt, d in G[now]:
            if nxt == now:
                continue     
            nxt_cost = dist[now] + d
            if nxt_cost < dist[nxt]:
                dist[nxt] = nxt_cost
                heappush(que, (nxt_cost, nxt))
        
    return dist[g]

ans = dijkstra(X-1, Y-1)
print(ans)
0