init
This commit is contained in:
commit
851751ea87
82 changed files with 2093 additions and 0 deletions
30
4A.py
Normal file
30
4A.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import sys
|
||||
import math
|
||||
|
||||
data = sys.stdin.read().split()
|
||||
n = int(data[0])
|
||||
xs = []
|
||||
ys = []
|
||||
idx = 1
|
||||
for _ in range(n):
|
||||
xs.append(int(data[idx]))
|
||||
ys.append(int(data[idx+1]))
|
||||
idx += 2
|
||||
min_e = [float('inf')] * n
|
||||
used = [False] * n
|
||||
min_e[0] = 0.0
|
||||
ans = 0.0
|
||||
for _ in range(n):
|
||||
v = -1
|
||||
for i in range(n):
|
||||
if not used[i] and (v == -1 or min_e[i] < min_e[v]):
|
||||
v = i
|
||||
used[v] = True
|
||||
ans += math.sqrt(min_e[v])
|
||||
vx, vy = xs[v], ys[v]
|
||||
for u in range(n):
|
||||
if not used[u]:
|
||||
dist_sq = (xs[u] - vx)**2 + (ys[u] - vy)**2
|
||||
if dist_sq < min_e[u]:
|
||||
min_e[u] = dist_sq
|
||||
print(f"{ans:.10f}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue