結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー Alex WiceAlex Wice
提出日時 2020-05-29 21:35:07
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,135 ms / 2,000 ms
コード長 1,222 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 77,184 KB
実行使用メモリ 195,144 KB
最終ジャッジ日時 2024-04-23 20:30:13
合計ジャッジ時間 26,760 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
78,080 KB
testcase_01 AC 90 ms
77,824 KB
testcase_02 AC 826 ms
138,308 KB
testcase_03 AC 904 ms
176,744 KB
testcase_04 AC 887 ms
177,252 KB
testcase_05 AC 668 ms
177,332 KB
testcase_06 AC 694 ms
176,952 KB
testcase_07 AC 202 ms
111,996 KB
testcase_08 AC 438 ms
189,540 KB
testcase_09 AC 147 ms
88,648 KB
testcase_10 AC 267 ms
131,808 KB
testcase_11 AC 227 ms
118,340 KB
testcase_12 AC 191 ms
94,592 KB
testcase_13 AC 740 ms
139,080 KB
testcase_14 AC 858 ms
152,500 KB
testcase_15 AC 1,021 ms
165,692 KB
testcase_16 AC 499 ms
116,428 KB
testcase_17 AC 1,065 ms
167,276 KB
testcase_18 AC 380 ms
105,596 KB
testcase_19 AC 1,003 ms
166,976 KB
testcase_20 AC 366 ms
103,808 KB
testcase_21 AC 420 ms
110,360 KB
testcase_22 AC 973 ms
160,348 KB
testcase_23 AC 102 ms
80,000 KB
testcase_24 AC 111 ms
80,512 KB
testcase_25 AC 177 ms
92,456 KB
testcase_26 AC 551 ms
128,068 KB
testcase_27 AC 593 ms
124,604 KB
testcase_28 AC 940 ms
152,484 KB
testcase_29 AC 222 ms
89,084 KB
testcase_30 AC 1,022 ms
163,300 KB
testcase_31 AC 697 ms
142,280 KB
testcase_32 AC 523 ms
120,660 KB
testcase_33 AC 1,135 ms
166,104 KB
testcase_34 AC 426 ms
107,924 KB
testcase_35 AC 970 ms
164,264 KB
testcase_36 AC 114 ms
80,780 KB
testcase_37 AC 163 ms
82,464 KB
testcase_38 AC 120 ms
81,280 KB
testcase_39 AC 151 ms
82,320 KB
testcase_40 AC 103 ms
79,744 KB
testcase_41 AC 1,001 ms
195,144 KB
testcase_42 AC 375 ms
115,044 KB
testcase_43 AC 606 ms
139,724 KB
testcase_44 AC 310 ms
100,228 KB
testcase_45 AC 571 ms
136,656 KB
testcase_46 AC 87 ms
77,824 KB
testcase_47 AC 88 ms
77,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

####
from collections import defaultdict as ddic
import heapq

def solve(N,M,X,Y,A,B):
    # A: powerpole locations
    # B: wires
    # Shortest path X to Y
    graph = ddic(list)
    for u, v in B:
        graph[u].append(v)
        graph[v].append(u)
    def dist_2d(u, v):
        x1, y1 = A[u - 1]
        x2, y2 = A[v - 1]
        return ((x1-x2)**2 + (y1-y2)**2)**0.5

    INF = float('inf')
    dist = ddic(lambda: INF)
    dist[X] = 0
    pq = [[0, X]]
    while pq:
        d, node = heapq.heappop(pq)
        if d > dist[node]: continue
        for nei in graph[node]:
            w = dist_2d(node, nei)
            d2 = d + w
            if d2 < dist[nei]:
                dist[nei] = d2
                heapq.heappush(pq, [d2, nei])
    return dist[Y]

    
    
N,M = rrm()
X,Y = rrm()
A = [rrm()  for _ in xrange(N)]
B = [rrm() for _ in xrange(M)]
print solve(N, M, X, Y, A, B)
0