Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
Xs,Ys,Xg,Yg=map(int,input().split())

N=int(input())

L=[(Xs,Ys,0)]
for i in range(N):
    x,y,r=map(int,input().split())
    L.append((x,y,r))
L.append((Xg,Yg,0))

C=[-1 for i in range(len(L))]
C[0]=0

X=Xs
Y=Ys
R=0
Q=[]
import heapq
heapq.heapify(Q)
Z=[]
for i in range(1,len(L)):
    if C[i]==-1:
        heapq.heappush(Q,(max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,0))
        #Z.append([max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,0])
#print(Z)
        
for j in range(10**7):
    if len(Q)==0:
        break
    else:
        if C[Q[0][1]]!=-1:
            qq=heapq.heappop(Q)
            
        else:
            q=heapq.heappop(Q)
            C[q[1]]=q[0]
            X=L[q[1]][0]
            Y=L[q[1]][1]
            R=L[q[1]][2]
            for i in range(1,len(L)):
                if C[i]==-1:
                    heapq.heappush(Q,(max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2]))+C[q[1]],i,q[1]))
                    #Z.append([max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,q[1]])
    if C[-1]!=-1:
        break
    #print(C)
    #print(Z)
print(C[-1])
#print(C)

Fixed submission:
import sys
input=sys.stdin.readline

Xs,Ys,Xg,Yg=map(int,input().split())
N=int(input())
L=[]
L.append([Xs,Ys,0])
for i in range(N):
    x,y,r=map(int,input().split())
    L.append([x,y,r])
L.append([Xg,Yg,0])
cost=[[-1 for i in range(N+2)]for j in range(N+2)]
for i in range(N+2):
    for j in range(i,N+2):
        cost[i][j]=max(0,((L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2)**0.5-L[i][2]-L[j][2])
        cost[j][i]=cost[i][j]
#print(cost)


def jdijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

#print(jdijkstra(0,N+2,(N+2)**2,cost))
ans=jdijkstra(0,N+2,(N+2)**2,cost)
print(ans[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
Xs,Ys,Xg,Yg=map(int,input().split())

N=int(input())

L=[(Xs,Ys,0)]
for i in range(N):
    x,y,r=map(int,input().split())
    L.append((x,y,r))
L.append((Xg,Yg,0))

C=[-1 for i in range(len(L))]
C[0]=0

X=Xs
Y=Ys
R=0
Q=[]
import heapq
heapq.heapify(Q)
Z=[]
for i in range(1,len(L)):
    if C[i]==-1:
        heapq.heappush(Q,(max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,0))
        #Z.append([max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,0])
#print(Z)
        
for j in range(10**7):
    if len(Q)==0:
        break
    else:
        if C[Q[0][1]]!=-1:
            qq=heapq.heappop(Q)
            
        else:
            q=heapq.heappop(Q)
            C[q[1]]=q[0]
            X=L[q[1]][0]
            Y=L[q[1]][1]
            R=L[q[1]][2]
            for i in range(1,len(L)):
                if C[i]==-1:
                    heapq.heappush(Q,(max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2]))+C[q[1]],i,q[1]))
                    #Z.append([max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,q[1]])
    if C[-1]!=-1:
        break
    #print(C)
    #print(Z)
print(C[-1])
#print(C)

Fixed submission:
import sys
input=sys.stdin.readline

Xs,Ys,Xg,Yg=map(int,input().split())
N=int(input())
L=[]
L.append([Xs,Ys,0])
for i in range(N):
    x,y,r=map(int,input().split())
    L.append([x,y,r])
L.append([Xg,Yg,0])
cost=[[-1 for i in range(N+2)]for j in range(N+2)]
for i in range(N+2):
    for j in range(i,N+2):
        cost[i][j]=max(0,((L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2)**0.5-L[i][2]-L[j][2])
        cost[j][i]=cost[i][j]
#print(cost)


def jdijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

#print(jdijkstra(0,N+2,(N+2)**2,cost))
ans=jdijkstra(0,N+2,(N+2)**2,cost)
print(ans[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
Xs,Ys,Xg,Yg=map(int,input().split())

N=int(input())

L=[[Xs,Ys,0]]
for i in range(N):
    x,y,r=map(int,input().split())
    L.append([x,y,r])
L.append([Xg,Yg,0])

C=[-1 for i in range(len(L))]
C[0]=0

X=Xs
Y=Ys
R=0
Q=[]
import heapq
heapq.heapify(Q)
Z=[]
for i in range(1,len(L)):
    if C[i]==-1:
        heapq.heappush(Q,[max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,0])
        #Z.append([max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,0])
#print(Z)
        
for j in range(10**7):
    if len(Q)==0:
        break
    else:
        if C[Q[0][1]]!=-1:
            qq=heapq.heappop(Q)
            
        else:
            q=heapq.heappop(Q)
            C[q[1]]=q[0]
            X=L[q[1]][0]
            Y=L[q[1]][1]
            R=L[q[1]][2]
            for i in range(1,len(L)):
                if C[i]==-1:
                    heapq.heappush(Q,[max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2]))+C[q[1]],i,q[1]])
                    #Z.append([max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,q[1]])
    if C[-1]!=-1:
        break
    #print(C)
    #print(Z)
print(C[-1])
#print(C)

Fixed submission:
import sys
input=sys.stdin.readline

Xs,Ys,Xg,Yg=map(int,input().split())
N=int(input())
L=[]
L.append([Xs,Ys,0])
for i in range(N):
    x,y,r=map(int,input().split())
    L.append([x,y,r])
L.append([Xg,Yg,0])
cost=[[-1 for i in range(N+2)]for j in range(N+2)]
for i in range(N+2):
    for j in range(i,N+2):
        cost[i][j]=max(0,((L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2)**0.5-L[i][2]-L[j][2])
        cost[j][i]=cost[i][j]
#print(cost)


def jdijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

#print(jdijkstra(0,N+2,(N+2)**2,cost))
ans=jdijkstra(0,N+2,(N+2)**2,cost)
print(ans[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
Xs,Ys,Xg,Yg=map(int,input().split())

N=int(input())

L=[[Xs,Ys,0]]
for i in range(N):
    x,y,r=map(int,input().split())
    L.append([x,y,r])
L.append([Xg,Yg,0])

C=[-1 for i in range(len(L))]
C[0]=0

X=Xs
Y=Ys
R=0
Q=[]
import heapq
heapq.heapify(Q)
Z=[]
for i in range(1,len(L)):
    if C[i]==-1:
        heapq.heappush(Q,[max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,0])
        Z.append([max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,0])
#print(Z)
        
for j in range(10**7):
    if len(Q)==0:
        break
    else:
        if C[Q[0][1]]!=-1:
            qq=heapq.heappop(Q)
            
        else:
            q=heapq.heappop(Q)
            C[q[1]]=q[0]
            X=L[q[1]][0]
            Y=L[q[1]][1]
            R=L[q[1]][2]
            for i in range(1,len(L)):
                if C[i]==-1:
                    heapq.heappush(Q,[max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2]))+C[q[1]],i,q[1]])
                    Z.append([max(0,((X-L[i][0])**2+(Y-L[i][1])**2)**0.5-(R+L[i][2])),i,q[1]])
    if C[-1]!=-1:
        break
    #print(C)
    #print(Z)
print(C[-1])
#print(C)

Fixed submission:
import sys
input=sys.stdin.readline

Xs,Ys,Xg,Yg=map(int,input().split())
N=int(input())
L=[]
L.append([Xs,Ys,0])
for i in range(N):
    x,y,r=map(int,input().split())
    L.append([x,y,r])
L.append([Xg,Yg,0])
cost=[[-1 for i in range(N+2)]for j in range(N+2)]
for i in range(N+2):
    for j in range(i,N+2):
        cost[i][j]=max(0,((L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2)**0.5-L[i][2]-L[j][2])
        cost[j][i]=cost[i][j]
#print(cost)


def jdijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

#print(jdijkstra(0,N+2,(N+2)**2,cost))
ans=jdijkstra(0,N+2,(N+2)**2,cost)
print(ans[-1])