Language: C++

#include<iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
#include <list>
#include <map>
#include <cmath>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <climits>
#include <queue>
#include <stack>

using namespace std;

const double EPS (1e-8);
const double PI = acos(-1.0);

template<class T>
struct Point{
	T x,y;
	Po() : x(0.0),y(0.0) {}
	Po(const T &x,const T &y) : x(x),y(y) {}
	Po operator+(const Po& a) const { return Po(x + a.x,y + a.y); }
	Po operator-(const Po& a) const { return Po(x - a.x,y - a.y); }
	Po operator*(const double& a) const { return Po(x * a, y * a); }
	Po operator/(const double& a) const { return Po(x / a, y / a); }
};

enum{ CCW = 1,CW = -1,ON = 0};

typedef Po<double> P;

double SQ(double x) {return x* x; }
double abs(const P& a) { return sqrt(SQ(a.x) + SQ(a.y)); }
double dot( const P& a,const P &b){ return a.x * b.x + a.y * b.y ; }
double cross( const P& a,const P &b){ return a.x * b.y - a.y * b.x ; }

P rot(const P& a, double theta){
	return P( a.x * cos(theta) - a.y * sin(theta) ,
		a.x * sin(theta) + a.y * cos(theta) );
}

int ccw(P a,P b,P c){
	b = b - a; c = c - a;
	double rdir = cross(b,c);
	double len = abs(b) * abs(c);
	if( rdir > EPS *len) return CCW;
	else if( rdir < -EPS * len) return CW;
	return ON;
}

bool intersect(P& a1,P& b1,P& a2, P& b2){
	if(max(a1.x,b1.x) + EPS < min(a2.x,b2.x)
	||max(a1.y,b1.y) + EPS < min(a2.y,b2.y)
	||max(a2.x,b2.x) + EPS < min(a1.x,b1.x)
	||max(a2.y,b2.y) + EPS < min(a1.y,b1.y) ) return false;
	return ccw(a1,b1,a2) * ccw(a1,b1,b2) <= 0
		&& ccw(a2,b2,a1) * ccw(a2,b2,b1) <= 0;
}

typedef pair<P,P> PD;

PD GetContact(const P& p, const P &q,double pr,double pq){
	P a = q-p;
	P b = rot(a,PI / 2);
	double c = abs(a);
	b = b / c;

	double s = (pr + pq + c) / 2;
	double men = sqrt(s * (s - pr) * (s - pq) * (s - c));
	double l = 2 * men / c;
	double lp = sqrt(SQ(pr) - SQ(l));
	
	a = a / c * lp;
	b = b * l;
	return PD(p + a + b,p + a - b);
}

int n;
P p[100];
double r[100];
double dp[202][202];

#define FOR(i,n) for(int i = 0; i < (n) ; i++)


int main(){

	while(cin>>n,n){
		vector<P> us;
		vector<PD> vpd;
		FOR(i,n) cin>>p[i].x >> p[i].y >> r[i];
		FOR(i,202) FOR(j,202) dp[i][j] = 1e50;
		us.push_back(p[0]);

		for (int i = 0; i < n - 1; i++){
			PD pd = GetContact(p[i],p[i+1],r[i],r[i+1]);
			us.push_back(pd.first);
			us.push_back(pd.second);
			vpd.push_back(pd);
		}
		us.push_back(p[n-1]);

		for(int i = 0; i < (int)us.size(); i++){
			for(int j = i + 1; j < (int)us.size(); j++){
				bool ok = true;
				int l  = (1 + i) / 2;
				int r = (1 + j) / 2 - 1;
				for (int k = l; k < r; k++){
					if(!intersect(us[i],us[j],vpd[k].first,vpd[k].second))
						ok = false;
				}
				if(!ok) continue;
				double dist = abs(us[i] - us[j]);
				dp[j][i] = dp[i][j] = dist;
			}
		}

		int a = (int)us.size();
		FOR(k,a) FOR(i,a) FOR(j,a) dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);

		printf("%.10lf\n",dp[0][a - 1]);

	}
	return 0;
}

Compiler output:
a.cc:26:9: error: ISO C++ forbids declaration of 'Po' with no type [-fpermissive]
   26 |         Po() : x(0.0),y(0.0) {}
      |         ^~
a.cc:27:9: error: ISO C++ forbids declaration of 'Po' with no type [-fpermissive]
   27 |         Po(const T &x,const T &y) : x(x),y(y) {}
      |         ^~
a.cc:28:9: error: 'Po' does not name a type
   28 |         Po operator+(const Po& a) const { return Po(x + a.x,y + a.y); }
      |         ^~
a.cc:29:9: error: 'Po' does not name a type
   29 |         Po operator-(const Po& a) const { return Po(x - a.x,y - a.y); }
      |         ^~
a.cc:30:9: error: 'Po' does not name a type
   30 |         Po operator*(const double& a) const { return Po(x * a, y * a); }
      |         ^~
a.cc:31:9: error: 'Po' does not name a type
   31 |         Po operator/(const double& a) const { return Po(x / a, y / a); }
      |         ^~
a.cc: In member function 'int Point<T>::Po()':
a.cc:26:16: error: only constructors take member initializers
   26 |         Po() : x(0.0),y(0.0) {}
      |                ^
a.cc:26:31: warning: no return statement in function returning non-void [-Wreturn-type]
   26 |         Po() : x(0.0),y(0.0) {}
      |                               ^
a.cc: In member function 'int Point<T>::Po(const T&, const T&)':
a.cc:27:37: error: only constructors take member initializers
   27 |         Po(const T &x,const T &y) : x(x),y(y) {}
      |                                     ^
a.cc:27:48: warning: no return statement in function returning non-void [-Wreturn-type]
   27 |         Po(const T &x,const T &y) : x(x),y(y) {}
      |                                                ^
a.cc: At global scope:
a.cc:36:9: error: 'Po' does not name a type
   36 | typedef Po<double> P;
      |         ^~
a.cc:39:18: error: 'P' does not name a type
   39 | double abs(const P& a) { return sqrt(SQ(a.x) + SQ(a.y)); }
      |                  ^
a.cc: In function 'double abs(const int&)':
a.cc:39:43: error: request for member 'x' in 'a', which is of non-class type 'const int'
   39 | double abs(const P& a) { return sqrt(SQ(a.x) + SQ(a.y)); }
      |                                           ^
a.cc:39:53: error: request for member 'y' in 'a', which is of non-class type 'const int'
   39 | double abs(const P& a) { return sqrt(SQ(a.x) + SQ(a.y)); }
      |                                                     ^
a.cc: At global scope:
a.cc:40:19: error: 'P' does not name a type
   40 | double dot( const P& a,const P &b){ return a.x * b.x + a.y * b.y ; }
      |                   ^
a.cc:40:30: error: 'P' does not name a type
   40 | double dot( const P& a,const P &b){ return a.x * b.x + a.y * b.y ; }
      |                              ^
a.cc: In function 'double dot(const int&, const int&)':
a.cc:40:46: error: request for member 'x' in 'a', which is of non-class type 'const int'
   40 | double dot( const P& a,const P &b){ return a.x * b.x + a.y * b.y ; }
      |                                              ^
a.cc:40:52: error: request for member 'x' in 'b', which is of non-class type 'const int'
   40 | double dot( const P& a,const P &b){ return a.x * b.x + a.y * b.y ; }
      |                                                    ^
a.cc:40:58: error: request for member 'y' in 'a', which is of non-class type 'const int'
   40 | double dot( const P& a,const P &b){ return a.x * b.x + a.y * b.y ; }
      |                                                          ^
a.cc:40:64: error: request for member 'y' in 'b', which is of non-class type 'const int'
   40 | double dot( const P& a,const P &b){ return a.x * b.x + a.y * b.y ; }
      |                                                                ^
a.cc: At global scope:
a.cc:41:21: error: 'P' does not name a type
   41 | double cross( const P& a,const P &b){ return a.x * b.y - a.y * b.x ; }
      |                     ^
a.cc:41:32: error: 'P' does not name a type
   41 | double cross( const P& a,const P &b){ return a.x * b.y - a.y * b.x ; }
      |                                ^
a.cc: In function 'double cross(const int&, const int&)':
a.cc:41:48: error: request for member 'x' in 'a', which is of non-class type 'const int'
   41 | double cross( const P& a,const P &b){ return a.x * b.y - a.y * b.x ; }
      |                                                ^
a.cc:41:54: error: request for member 'y' in 'b', which is of non-class type 'const int'
   41 | double cross( const P& a,const P &b){ return a.x * b.y - a.y * b.x ; }
      |                                                      ^
a.cc:41:60: error: request for member 'y' in 'a', which is of non-class type 'const int'
   41 | double cross( const P& a,const P &b){ return a.x * b.y - a.y * b.x ; }
      |                                                            ^
a.cc:41:66: error: request for member 'x' in 'b', which is of non-class type 'const int'
   41 | double cross( const P& a,const P &b){ return a.x * b.y - a.y * b.x ; }
      |                                                                  ^
a.cc: At global scope:
a.cc:43:1: error: 'P' does not name a type
   43 | P rot(const P& a, double theta){
      | ^
a.cc:48:9: error: 'P' was not declared in this scope; did you mean 'PI'?
   48 | int ccw(P a,P b,P c){
      |         ^
      |         PI
a.cc:48:13: error: 'P' was not declared in this scope; did you mean 'PI'?
   48 | int ccw(P a,P b,P c){
      |             ^
      |             PI
a.cc:48:17: error: 'P' was not declared in this scope; did you mean 'PI'?
   48 | int ccw(P a,P b,P c){
      |                 ^
      |                 PI
a.cc:48:20: error: expression list treated as compound expression in initializer [-fpermissive]
   48 | int ccw(P a,P b,P c){
      |                    ^
a.cc:57:16: error: 'P' was not declared in this scope; did you mean 'PI'?
   57 | bool intersect(P& a1,P& b1,P& a2, P& b2){
      |                ^
      |                PI
a.cc:57:19: error: 'a1' was not declared in this scope; did you mean 'y1'?
   57 | bool intersect(P& a1,P& b1,P& a2, P& b2){
      |                   ^~
      |                   y1
a.cc:57:22: error: 'P' was not declared in this scope; did you mean 'PI'?
   57 | bool intersect(P& a1,P& b1,P& a2, P& b2){
      |                      ^
      |                      PI
a.cc:57:25: error: 'b1' was not declared in this scope; did you mean 'y1'?
   57 | bool intersect(P& a1,P& b1,P& a2, P& b2){
      |                         ^~
      |                         y1
a.cc:57:28: error: 'P' was not declared in this scope; did you mean 'PI'?
   57 | bool intersect(P& a1,P& b1,P& a2, P& b2){
      |                            ^
      |                            PI
a.cc:57:31: error: 'a2' was not declared in this scope
   57 | bool intersect(P& a1,P& b1,P& a2, P& b2){
      |                               ^~
a.cc:57:35: error: 'P' was not declared in this scope; did you mean 'PI'?
   57 | bool intersect(P& a1,P& b1,P& a2, P& b2){
      |                                   ^
      |                                   PI
a.cc:57:38: error: 'b2' was not declared in this scope
   57 | bool intersect(P& a1,P& b1,P& a2, P& b2){
      |                                      ^~
a.cc:57:40: error: expression list treated as compound expression in initializer [-fpermissive]
   57 | bool intersect(P& a1,P& b1,P& a2, P& b2){
      |                                        ^
a.cc:66:14: error: 'P' was not declared in this scope; did you mean 'PI'?
   66 | typedef pair<P,P> PD;
      |              ^
      |              PI
a.cc:66:16: error: 'P' was not declared in this scope; did you mean 'PI'?
   66 | typedef pair<P,P> PD;
      |                ^
      |                PI
a.cc:66:17: error: template argument 1 is invalid
   66 | typedef pair<P,P> PD;
      |                 ^
a.cc:66:17: error: template argument 2 is invalid
a.cc:68:21: error: 'P' does not name a type; did you mean 'PD'?
   68 | PD GetContact(const P& p, const P &q,double pr,double pq){
      |                     ^
      |                     PD
a.cc:68:33: error: 'P' does not name a type; did you mean 'PD'?
   68 | PD GetContact(const P& p, const P &q,double pr,double pq){
      |                                 ^
      |                                 PD
a.cc: In function 'PD GetContact(const int&, const int&, double, double)':
a.cc:69:9: error: 'P' was not declared in this scope
   69 |         P a = q-p;
      |         ^
a.cc:70:10: error: expected ';' before 'b'
   70 |         P b = rot(a,PI / 2);
      |          ^~
      |          ;
a.cc:71:24: error: 'a' was not declared in this scope
   71 |         double c = abs(a);
      |                        ^
a.cc:72:9: error: 'b' was not declared in this scope
   72 |         b = b / c;
      |         ^
a.cc:81:38: error: expression list treated as compound expression in functional cast [-fpermissive]
   81 |         return PD(p + a + b,p + a - b);
      |                                      ^
a.cc: At global scope:
a.cc:85:1: error: 'P' does not name a type; did you mean 'PD'?
   85 | P p[100];
      | ^
      | PD
a.cc: In function 'int main()':
a.cc:95:24: error: 'P' was not declared in this scope
   95 |                 vector<P> us;
      |                        ^
a.cc:95:25: error: template argument 1 is invalid
   95 |                 vector<P> us;
      |                         ^
a.cc:95:25: error: template argument 2 is invalid
a.cc:97:31: error: 'p' was not declared in this scope
   97 |                 FOR(i,n) cin>>p[i].x >> p[i].y >> r[i];
      |                               ^
a.cc:99:20: error: request for member 'push_back' in 'us', which is of non-class type 'int'
   99 |                 us.push_back(p[0]);
      |                    ^~~~~~~~~
a.cc:99:30: error: 'p' was not declared in this scope
   99 |                 us.push_back(p[0]);
      |                              ^
a.cc:103:28: error: request for member 'push_back' in 'us', which is of non-class type 'int'
  103 |                         us.push_back(pd.first);
      |                            ^~~~~~~~~
a.cc:103:41: error: request for member 'first' in 'pd', which is of non-class type 'PD' {aka 'int'}
  103 |                         us.push_back(pd.first);
      |