Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1, 0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2, 0])


def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) - x[2] - y[2])


que = [[0, 0]]
heapq.heapify(que)
mi = [10 ** 16] * (n + 2)
mi[0] = 0
used = [False]*(n+2)

while que:
    w, x = heapq.heappop(que)
    if x == n + 1:
        break
    if used[x]:
        continue
    used[x] = True
    for i in range(n + 2):
        if used[i]:
            continue
        cost = dif(xy[x], xy[i])
        if (not used[i]) and w + cost < mi[i]:
            mi[i] = w + cost
            heapq.heappush(que, [w + cost, i])
print(mi[-1])


Fixed submission:
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1, 0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2, 0])


def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) - x[2] - y[2])




q = set([i for i in range(n + 2)])
mi = [10 ** 16] * (n + 2)
mi[0] = 0

while q:
    u = -1
    mm = 10**16
    for i in q:
        if mm > mi[i]:
            mm = mi[i]
            u = i
    
    q.remove(u)
    for i in q:
        mi[i] = min(mi[i], mi[u] + dif(xy[i], xy[u]))

print(mi[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1, 0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2, 0])


def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) - x[2] - y[2])


que = [[0, 0]]
heapq.heapify(que)
mi = [10 ** 16] * (n + 2)
mi[0] = 0
used = [False]*(n+2)

while que:
    w, x = heapq.heappop(que)
    if x == n + 1:
        break
    if used[x]:
        continue
    used[x] = True
    for i in range(n + 2):
        if used[i]:
            continue
        cost = dif(xy[x], xy[i])
        if w + cost < mi[i]:
            mi[i] = w + cost
            heapq.heappush(que, [w + cost, i])
print(mi[-1])


Fixed submission:
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1, 0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2, 0])


def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) - x[2] - y[2])




q = set([i for i in range(n + 2)])
mi = [10 ** 16] * (n + 2)
mi[0] = 0

while q:
    u = -1
    mm = 10**16
    for i in q:
        if mm > mi[i]:
            mm = mi[i]
            u = i
    
    q.remove(u)
    for i in q:
        mi[i] = min(mi[i], mi[u] + dif(xy[i], xy[u]))

print(mi[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1,0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2,0])

def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0])** 2 + (x[1] - y[1])** 2) - x[2] - y[2])


que = [[0, 0]]
heapq.heapify(que)
mi = [10 ** 16] * (n + 2)
mi[0] = 0
used = [False]*(n+2)

while que:
    w, x = heapq.heappop(que)
    used[x]=True
    for i in range(n + 2):
        if used[i]:
            continue
        cost = dif(xy[x], xy[i])
        if w + cost < mi[i]:
            mi[i] = w + cost
            heapq.heappush(que,[w + cost, i])
print(mi[-1])

    

Fixed submission:
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1, 0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2, 0])


def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) - x[2] - y[2])




q = set([i for i in range(n + 2)])
mi = [10 ** 16] * (n + 2)
mi[0] = 0

while q:
    u = -1
    mm = 10**16
    for i in q:
        if mm > mi[i]:
            mm = mi[i]
            u = i
    
    q.remove(u)
    for i in q:
        mi[i] = min(mi[i], mi[u] + dif(xy[i], xy[u]))

print(mi[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1,0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2,0])

def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0])** 2 + (x[1] - y[1])** 2) - x[2] - y[2])


que = [[0, 0]]
heapq.heapify(que)
mi = [10 ** 16] * (n + 2)
mi[0] = 0

while que:
    w, x = heapq.heappop(que)
    for i in range(n + 2):
        if i == x:
            continue
        cost = dif(xy[x], xy[i])
        if w + cost < mi[i]:
            mi[i] = w + cost
            heapq.heappush(que,[w + cost, i])
print(mi[-1])

    

Fixed submission:
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1, 0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2, 0])


def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) - x[2] - y[2])




q = set([i for i in range(n + 2)])
mi = [10 ** 16] * (n + 2)
mi[0] = 0

while q:
    u = -1
    mm = 10**16
    for i in q:
        if mm > mi[i]:
            mm = mi[i]
            u = i
    
    q.remove(u)
    for i in q:
        mi[i] = min(mi[i], mi[u] + dif(xy[i], xy[u]))

print(mi[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1,0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2,0])

def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0])** 2 + (x[1] - y[1])** 2) - x[2] - y[2])


que = [[0, 0]]
heapq.heapify(que)
mi = [10 ** 16] * (n + 2)
mi[0] = 0

while que:
    w, x = heapq.heappop(que)
    for i in range(n + 2):
        if i == x:
            continue
        cost = dif(xy[x], xy[i])
        if w + cost < mi[i]:
            mi[i] = w + cost
            heapq.heappush(que,[w + cost, i])
print(mi[-1])

    

Fixed submission:
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1, 0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2, 0])


def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) - x[2] - y[2])




q = set([i for i in range(n + 2)])
mi = [10 ** 16] * (n + 2)
mi[0] = 0

while q:
    u = -1
    mm = 10**16
    for i in q:
        if mm > mi[i]:
            mm = mi[i]
            u = i
    
    q.remove(u)
    for i in q:
        mi[i] = min(mi[i], mi[u] + dif(xy[i], xy[u]))

print(mi[-1])