結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー |
![]() |
提出日時 | 2020-05-29 22:03:52 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,802 ms / 2,000 ms |
コード長 | 767 bytes |
コンパイル時間 | 228 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 106,488 KB |
最終ジャッジ日時 | 2024-11-06 04:46:41 |
合計ジャッジ時間 | 37,291 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 46 |
ソースコード
import heapqimport mathimport sysinput = sys.stdin.buffer.readlinesys.setrecursionlimit(10 ** 7)N, M = map(int, input().split())S, T = map(int, input().split())xy = tuple(tuple(map(int, input().split())) for _ in range(N))edge = [[] for _ in range(N + 1)]for _ in range(M):p, q = map(int, input().split())x1, y1 = xy[p - 1]x2, y2 = xy[q - 1]d = math.hypot(x1 - x2, y1 - y2)edge[p].append((q, d))edge[q].append((p, d))inf = 10**18dist = [inf] * (N + 1)dist[S] = 0que = [(0, S)]while que:c, s = heapq.heappop(que)if dist[s] < c:continuecost = dist[s]for t, d in edge[s]:if dist[t] > cost + d:dist[t] = cost + dheapq.heappush(que, (cost+d, t))print(dist[T])