stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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]);

}

// Fastest known solution for this problem: