stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<cstdio>

#include<cmath>

#include<queue>

#include<vector>

#include<cstring>

#include<algorithm>

#define maxn 1005

using namespace std;

int xs,ys,xt,yt,n,x[maxn],y[maxn],r[maxn];

double dist[maxn],g[maxn][maxn];

queue<int> q;

bool inq[maxn];

int main()

{

	scanf("%d%d%d%d%d",&xs,&ys,&xt,&yt,&n);

	x[0]=xs,y[0]=ys,x[n+1]=xt,y[n+1]=yt;

	for(int i=1;i<=n;i++) scanf("%d%d%d",&x[i],&y[i],&r[i]);

	for(int i=0;i<=n+1;i++)

		for(int j=0;j<=n+1;j++)

			g[i][j]=max(0.0,sqrt(1.0*(x[i]-x[j])*(x[i]-x[j])+1.0*(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j]);

	for(int i=1;i<=n+1;i++) dist[i]=1e16;

	q.push(0); inq[0]=true;

	while(!q.empty())

	{

		int u=q.front(); q.pop();

		inq[u]=false;

		for(int v=0;v<=n+1;v++)

			if(dist[v]>dist[u]+g[u][v])

			{

				dist[v]=dist[u]+g[u][v];

				if(!inq[v]) { inq[v]=true; q.push(v); }

			}

	}

	printf("%.10f\n",dist[n+1]);

}

// Faster C++ solution for the same problem (measured speedup: 4.029697924318275x):
#include<cstdio>

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

double f[1005][1005],dis[1005],a[1005][3];

bool b[1005];

int main()

{

	int i,j,k,n;

	double xi,xs,ys,xt,yt;

	scanf("%lf%lf%lf%lf",&xs,&ys,&xt,&yt);

	scanf("%d",&n);

	a[0][0]=xs;a[0][1]=ys;a[0][2]=0;

	a[n+1][0]=xt;a[n+1][1]=yt;a[n+1][2]=0;

	for(i=1;i<=n;i++)

		scanf("%lf%lf%lf",&a[i][0],&a[i][1],&a[i][2]);

	n++;

	for(i=0;i<=n;i++)

		for(j=i+1;j<=n;j++){

			f[i][j]=f[j][i]=sqrt((a[i][0]-a[j][0])*(a[i][0]-a[j][0])+(a[i][1]-a[j][1])*(a[i][1]-a[j][1]))-(a[i][2]+a[j][2]);

			if(f[i][j]<0)

				f[j][i]=f[i][j]=0;

		}

	for(i=0;i<=1003;i++) dis[i]=1e18;

	dis[0]=0; 

	for(i=0;i<n;i++){ 

		xi=1e18;

		k=0; 

		for(j=0;j<=n;j++){

            if(b[j]==0&&dis[j]<xi){ 

				xi=dis[j]; 

				k=j; 

			} 

        }

		b[k]=1; 

		for(j=0;j<=n;j++)

			dis[j]=min(dis[j],dis[k]+f[k][j]);

	}

	printf("%.9lf",dis[n]);

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <iomanip>

#include <cstring>

#include <string>

#include <vector>

#include <queue>

#include <cmath>

using namespace std;



const int MAXN = 1000 + 10;



#define y1 MyY1

#define y2 MyY2

struct barrier

{

    int x, y, r;

};



int N;

int x1, x2, y1, y2;

vector <barrier> vbar;

double dist[MAXN];

bool inQueue[MAXN];



double precalcDist[MAXN][MAXN];

double getDist(int from, int to)

{

    double deltaX = vbar[from].x - vbar[to].x;

    double deltaY = vbar[from].y - vbar[to].y;

    return max(sqrt(deltaX * deltaX + deltaY * deltaY) - vbar[from].r - vbar[to].r, 0.0);

}



void SPFA()

{

    fill(dist, dist + N + 2, 1e100);

    memset(inQueue, 0x00, sizeof inQueue);



    queue <int> q;

    q.push(0);

    dist[0] = 0, inQueue[0] = true;



    while(!q.empty())

    {

        int to = q.front();

        inQueue[to] = false;

        q.pop();



        for(int i = 0; i <= N + 1; i++)

        {

            if(i == to)

                continue;



            if(dist[i] > dist[to] + precalcDist[i][to])

            {

                dist[i] = dist[to] + precalcDist[i][to];

                if(!inQueue[i])

                {

                    inQueue[i] = true;

                    q.push(i);

                }

            }

        }

    }

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);



    int u, v, w;



    cin >> x1 >> y1 >> x2 >> y2 ;

    vbar.push_back(barrier{x1, y1, 0});

    vbar.push_back(barrier{x2, y2, 0});



    cin >> N ;

    for(int i = 1; i <= N; i++)

        cin >> u >> v >> w, vbar.push_back(barrier{u, v, w});



    for(int i = 0; i <= N + 1; i++)

        for(int j = 0; j < i; j++)

            precalcDist[i][j] = precalcDist[j][i] = getDist(i, j);



    SPFA();



    cout << fixed << setprecision(10) << dist[1] << endl ;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.447541401578356x):
#include<cstdio>

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

double f[1005][1005],dis[1005],a[1005][3];

bool b[1005];

int main()

{

	int i,j,k,n;

	double xi,xs,ys,xt,yt;

	scanf("%lf%lf%lf%lf",&xs,&ys,&xt,&yt);

	scanf("%d",&n);

	a[0][0]=xs;a[0][1]=ys;a[0][2]=0;

	a[n+1][0]=xt;a[n+1][1]=yt;a[n+1][2]=0;

	for(i=1;i<=n;i++)

		scanf("%lf%lf%lf",&a[i][0],&a[i][1],&a[i][2]);

	n++;

	for(i=0;i<=n;i++)

		for(j=i+1;j<=n;j++){

			f[i][j]=f[j][i]=sqrt((a[i][0]-a[j][0])*(a[i][0]-a[j][0])+(a[i][1]-a[j][1])*(a[i][1]-a[j][1]))-(a[i][2]+a[j][2]);

			if(f[i][j]<0)

				f[j][i]=f[i][j]=0;

		}

	for(i=0;i<=1003;i++) dis[i]=1e18;

	dis[0]=0; 

	for(i=0;i<n;i++){ 

		xi=1e18;

		k=0; 

		for(j=0;j<=n;j++){

            if(b[j]==0&&dis[j]<xi){ 

				xi=dis[j]; 

				k=j; 

			} 

        }

		b[k]=1; 

		for(j=0;j<=n;j++)

			dis[j]=min(dis[j],dis[k]+f[k][j]);

	}

	printf("%.9lf",dis[n]);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define F(i,a,b) for(int i=(a);i<=(b);++i)

#define F2(i,a,b) for(int i=(a);i<(b);++i)

#define dF(i,a,b) for(int i=(a);i>=(b);--i)

#define dF2(i,a,b) for(int i=(a);i>(b);--i)

#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)

using namespace std;



long double tx,ty;

int n;

long double x[1005],y[1005],r[1005];

bool vis[1005];

long double dis[1005];



long double d(int p,int q){return max((long double)0,sqrt((x[p]-x[q])*(x[p]-x[q])+(y[p]-y[q])*(y[p]-y[q]))-r[p]-r[q]);}



int main(){

	cin>>x[0]>>y[0]>>tx>>ty;

	scanf("%d",&n); x[n+1]=tx, y[n+1]=ty;

	F(i,1,n) cin>>x[i]>>y[i]>>r[i];

	F(i,1,n+2) dis[i]=1e20;

	int now=0; vis[0]=1;

	F(k,1,n+2){

		F(i,1,n+1) dis[i]=min(dis[i],dis[now]+d(now,i));

		int nxt=n+2;

		F(i,1,n+1) if(!vis[i]&&dis[nxt]>dis[i]) nxt=i;

		vis[nxt]=1;

		now=nxt;

	}

	printf("%.15lf",(double)dis[n+1]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.632884630315489x):
#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

const int MAXN = 1005;

const double eps = 1e-12;





int xs, ys, xt, yt, n;

struct node

{

	int x, y, z;

}p[MAXN];

double f[MAXN][MAXN], dis[MAXN];



double dist(int x, int y, int u, int v)

{

	return sqrt(1.0 * (1ll * (x-u) * (x-u) + 1ll * (y-v) * (y-v)));

}



double calc(int i, int j)

{

	double d = dist(p[i].x, p[i].y, p[j].x, p[j].y);

	if(p[i].z + p[j].z - d < eps) return d - p[i].z - p[j].z;

	return 0;

}



bool vis[MAXN];



int main ()

{

	scanf("%d%d%d%d", &xs, &ys, &xt, &yt);

	scanf("%d", &n); n++;

	for(int i = 1; i < n; i++)

		scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].z);

	p[0].x = xs, p[0].y = ys, p[0].z = 0;

	p[n].x = xt, p[n].y = yt, p[n].z = 0;

	for(int i = 0; i <= n; i++)

		for(int j = i; j <= n; j++)

			f[i][j] = f[j][i] = calc(i, j);

	memset(dis, 127, sizeof dis); dis[0] = 0;

	for(int i = 1; i <= n; i++)

	{

		int k = -1;

		for(int j = 0; j <= n; j++)

			if(!vis[j] && (k == -1 || dis[j] - dis[k] < eps))

				k = j;

		if(k < 0) break;

		vis[k] = 1;

		for(int j = 0; j <= n; j++)

			if(!vis[j] && dis[k] + f[k][j] - dis[j] < eps)

				dis[j] = dis[k] + f[k][j];

	}

	printf("%.10lf\n", dis[n]);

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#define max(a,b) (a>b?a:b)

using namespace std;

double d[1010],map[1010][1010];

double x[1010],y[1010],r[1010];

bool v[1010];

double tx,ty;

int n;

int main(){

    cin>>x[0]>>y[0]>>tx>>ty>>n;

    x[n+1]=tx,y[n+1]=ty;

    for(int i=1;i<=n;i++) cin>>x[i]>>y[i]>>r[i];

    for(int i=0;i<=n+1;i++)

        for(int j=0;j<=n+1;j++){

            if(i==j) continue;

            double ls=(sqrt((double) (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-(r[i]+r[j]));

            map[i][j]=max(ls,0);

        }

    for(int i=1;i<=n+1;i++) d[i]=(double) 1e10;

    int now=0;

    double mini;

    while(!v[now]){

        v[now]=true;

        for(int i=0;i<=n+1;i++){

            if(now==i) continue;

            if(!v[i]&&d[now]+map[now][i]<d[i])

                d[i]=d[now]+map[now][i];

        }

        mini=(double) 1e10;

        for(int i=0;i<=n+1;i++)

            if(!v[i]&&d[i]<mini) now=i,mini=d[i];

    }

    printf("%.10lf\n",d[n+1]);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.607728697264048x):
#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

const int MAXN = 1005;

const double eps = 1e-12;





int xs, ys, xt, yt, n;

struct node

{

	int x, y, z;

}p[MAXN];

double f[MAXN][MAXN], dis[MAXN];



double dist(int x, int y, int u, int v)

{

	return sqrt(1.0 * (1ll * (x-u) * (x-u) + 1ll * (y-v) * (y-v)));

}



double calc(int i, int j)

{

	double d = dist(p[i].x, p[i].y, p[j].x, p[j].y);

	if(p[i].z + p[j].z - d < eps) return d - p[i].z - p[j].z;

	return 0;

}



bool vis[MAXN];



int main ()

{

	scanf("%d%d%d%d", &xs, &ys, &xt, &yt);

	scanf("%d", &n); n++;

	for(int i = 1; i < n; i++)

		scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].z);

	p[0].x = xs, p[0].y = ys, p[0].z = 0;

	p[n].x = xt, p[n].y = yt, p[n].z = 0;

	for(int i = 0; i <= n; i++)

		for(int j = i; j <= n; j++)

			f[i][j] = f[j][i] = calc(i, j);

	memset(dis, 127, sizeof dis); dis[0] = 0;

	for(int i = 1; i <= n; i++)

	{

		int k = -1;

		for(int j = 0; j <= n; j++)

			if(!vis[j] && (k == -1 || dis[j] - dis[k] < eps))

				k = j;

		if(k < 0) break;

		vis[k] = 1;

		for(int j = 0; j <= n; j++)

			if(!vis[j] && dis[k] + f[k][j] - dis[j] < eps)

				dis[j] = dis[k] + f[k][j];

	}

	printf("%.10lf\n", dis[n]);

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<queue>

#define SF scanf

#define PF printf

#define MAXN 1010

using namespace std;

typedef long long ll;

double stx,sty,edx,edy;

int n;

struct node{

	double x,y,r;	

}p[MAXN];

double lenp(double x,double y,double xx,double yy){

	return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));

}

double len(int x,int y){

	double distx=lenp(p[x].x,p[x].y,p[y].x,p[y].y);

	return max(0.0,distx-p[x].r-p[y].r);

}

double len1[MAXN][MAXN];

double dist[MAXN];

int inq[MAXN];

queue<int> q;

void spfa(){

	while(!q.empty()){

		int x=q.front();

		inq[x]=0;

		q.pop();

		for(int i=1;i<=n;i++){

			if(i==x)

				continue;

			if(dist[i]<0||dist[i]>dist[x]+len1[x][i]){

				dist[i]=dist[x]+len(x,i);

				if(inq[i]==0){

					inq[i]=1;

					q.push(i);	

				}

			}

		}

	}

}	

int main(){

	SF("%lf%lf%lf%lf",&stx,&sty,&edx,&edy);

	SF("%d",&n);

	for(int i=1;i<=n;i++)

		SF("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);

	p[++n].x=stx;

	p[n].y=sty;

	p[n].r=0;

	p[++n].x=edx;

	p[n].y=edy;

	p[n].r=0;

	for(int i=1;i<=n;i++)

		for(int j=1;j<=n;j++)

			len1[i][j]=len(i,j);

	for(int i=1;i<=n;i++)

		dist[i]=-1;

		

	dist[n]=0;

	q.push(n);

	spfa();

	PF("%.10lf\n",dist[n-1]);

}

	

// Faster C++ solution for the same problem (measured speedup: 4.280905064156573x):
#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

const int MAXN = 1005;

const double eps = 1e-12;





int xs, ys, xt, yt, n;

struct node

{

	int x, y, z;

}p[MAXN];

double f[MAXN][MAXN], dis[MAXN];



double dist(int x, int y, int u, int v)

{

	return sqrt(1.0 * (1ll * (x-u) * (x-u) + 1ll * (y-v) * (y-v)));

}



double calc(int i, int j)

{

	double d = dist(p[i].x, p[i].y, p[j].x, p[j].y);

	if(p[i].z + p[j].z - d < eps) return d - p[i].z - p[j].z;

	return 0;

}



bool vis[MAXN];



int main ()

{

	scanf("%d%d%d%d", &xs, &ys, &xt, &yt);

	scanf("%d", &n); n++;

	for(int i = 1; i < n; i++)

		scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].z);

	p[0].x = xs, p[0].y = ys, p[0].z = 0;

	p[n].x = xt, p[n].y = yt, p[n].z = 0;

	for(int i = 0; i <= n; i++)

		for(int j = i; j <= n; j++)

			f[i][j] = f[j][i] = calc(i, j);

	memset(dis, 127, sizeof dis); dis[0] = 0;

	for(int i = 1; i <= n; i++)

	{

		int k = -1;

		for(int j = 0; j <= n; j++)

			if(!vis[j] && (k == -1 || dis[j] - dis[k] < eps))

				k = j;

		if(k < 0) break;

		vis[k] = 1;

		for(int j = 0; j <= n; j++)

			if(!vis[j] && dis[k] + f[k][j] - dis[j] < eps)

				dis[j] = dis[k] + f[k][j];

	}

	printf("%.10lf\n", dis[n]);

}
// Slower C++ solution:
#include<cstdio>

#include<queue>

#include<cmath>

#include<algorithm>

using namespace std;

const int MAXN=1005;



struct Point

{

	int x,y;

	Point(int _x=0,int _y=0)

	{x=_x;y=_y;}

};



int n;

double dis[MAXN][MAXN],f[MAXN];

int r[MAXN];

Point S,T,P[MAXN];

queue<int> Q;

bool inq[MAXN];



int main()

{

	scanf("%d%d%d%d",&S.x,&S.y,&T.x,&T.y);

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

		scanf("%d%d%d",&P[i].x,&P[i].y,&r[i]);

	P[0]=S;P[n+1]=T;

	for(int i=0;i<=n+1;i++)

		for(int j=0;j<=i;j++)

			dis[i][j]=dis[j][i]=max(0.0,sqrt(1.0*(P[i].x-P[j].x)*(P[i].x-P[j].x)+1.0*(P[i].y-P[j].y)*(P[i].y-P[j].y))-r[i]-r[j]);

	

	for(int i=1;i<=n+1;i++)

		f[i]=1e100;

	

	f[0]=0;

	Q.push(0);

	inq[0]=true;

	while(!Q.empty())

	{

		int u=Q.front();

		Q.pop();

		inq[u]=false;

		for(int i=0;i<=n+1;i++)

			if(i!=u)

				if(f[u]+dis[u][i]<f[i])

				{

					f[i]=f[u]+dis[u][i];

					if(!inq[i])

					{

						inq[i]=true;

						Q.push(i);

					}

				}

	}

	

	printf("%.10lf\n",f[n+1]);

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.290580347700734x):
#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

const int MAXN = 1005;

const double eps = 1e-12;





int xs, ys, xt, yt, n;

struct node

{

	int x, y, z;

}p[MAXN];

double f[MAXN][MAXN], dis[MAXN];



double dist(int x, int y, int u, int v)

{

	return sqrt(1.0 * (1ll * (x-u) * (x-u) + 1ll * (y-v) * (y-v)));

}



double calc(int i, int j)

{

	double d = dist(p[i].x, p[i].y, p[j].x, p[j].y);

	if(p[i].z + p[j].z - d < eps) return d - p[i].z - p[j].z;

	return 0;

}



bool vis[MAXN];



int main ()

{

	scanf("%d%d%d%d", &xs, &ys, &xt, &yt);

	scanf("%d", &n); n++;

	for(int i = 1; i < n; i++)

		scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].z);

	p[0].x = xs, p[0].y = ys, p[0].z = 0;

	p[n].x = xt, p[n].y = yt, p[n].z = 0;

	for(int i = 0; i <= n; i++)

		for(int j = i; j <= n; j++)

			f[i][j] = f[j][i] = calc(i, j);

	memset(dis, 127, sizeof dis); dis[0] = 0;

	for(int i = 1; i <= n; i++)

	{

		int k = -1;

		for(int j = 0; j <= n; j++)

			if(!vis[j] && (k == -1 || dis[j] - dis[k] < eps))

				k = j;

		if(k < 0) break;

		vis[k] = 1;

		for(int j = 0; j <= n; j++)

			if(!vis[j] && dis[k] + f[k][j] - dis[j] < eps)

				dis[j] = dis[k] + f[k][j];

	}

	printf("%.10lf\n", dis[n]);

}