init
This commit is contained in:
commit
851751ea87
82 changed files with 2093 additions and 0 deletions
33
3D.py
Normal file
33
3D.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
data = open(0).read().split()
|
||||
if not data:
|
||||
exit()
|
||||
n = int(data[0])
|
||||
x = [0] * n
|
||||
y = [0] * n
|
||||
idx = 1
|
||||
for i in range(n):
|
||||
x[i] = int(data[idx])
|
||||
y[i] = int(data[idx+1])
|
||||
idx += 2
|
||||
s = int(data[idx]) - 1
|
||||
t = int(data[idx+1]) - 1
|
||||
INF = 10**18
|
||||
D = [INF] * n
|
||||
D[s] = 0
|
||||
unvisited = list(range(n))
|
||||
get_D = D.__getitem__
|
||||
while unvisited:
|
||||
u = min(unvisited, key=get_D)
|
||||
if u == t or D[u] == INF:
|
||||
break
|
||||
unvisited.remove(u)
|
||||
du = D[u]
|
||||
xu = x[u]
|
||||
yu = y[u]
|
||||
for v in unvisited:
|
||||
dx = xu - x[v]
|
||||
dy = yu - y[v]
|
||||
cost = du + dx * dx + dy * dy
|
||||
if cost < D[v]:
|
||||
D[v] = cost
|
||||
print(D[t])
|
||||
Loading…
Add table
Add a link
Reference in a new issue