Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)

class UnionFindTree{

private:
  // indexツづ個青板づ個親ツノツーツド
  vector<int> par;
  // indexツづーツ債ェツづつキツづゥツ姪伉づ個δ可δ督ク
  vector<int> rank;
  // ツ姪伉づ個催妥・ツ値
  int treeSize;
  
public:
  UnionFindTree(int initTreeSize = 1000){
     // ツ暗クツ青板づ与ツつヲツづァツづェツつスツ値ツづーツ催妥・ツ格ツ納ツ青板づつキツづゥUnionFindTreeツづ個催ャツ青ャ
    treeSize = initTreeSize;
    init();
  }
  
  
  void init(){
    
    for(int i = 0; i < treeSize; i++){
      par.push_back(i);
      rank.push_back(0);
    }
    
  }

  // ツ与ツつヲツづァツづェツつスツ青板つェツ格ツ納ツつウツづェツづつ「ツづゥツ姪伉づ個δ仰ーツトツづーツ探ツ催オ
  int find(int x){
    
    if(par[x] == x){
      return x;
    }
    else{
      return par[x] = find(par[x]);
    }
    
  }
  
  void unite(int x,int y){
    
    x = find(x);
    y = find(y);
    
    if(x == y)
      return;
    
    if(rank[x] < rank[y]){
      par[x] = y;
    }
    else{
      par[y] = x;
      if(rank[y] == rank[x]){
	rank[x]++;
      }
    }
    
  }
  
  bool same(int x,int y){
    return find(x) == find(y);
  }

};
class Circle{
public:
	double x,y,z,r;
	Circle(){}
	Circle(double x_,double y_,double z_,double r_){
		x=x_;
		y=y_;
		z=z_;
		r=r_;
	}
};

const int MAX_V = 200;

double cost[MAX_V][MAX_V];
double mincost[MAX_V];
bool used[MAX_V];

int V;
const int INF = 10000000;

double prim(){
	for(int i = 0; i < V; i++){
		mincost[i] = INF;
		used[i] = false;
	}
	mincost[0] = 0;
	double res = 0;
	while(1){
		int v = -1;
		// Xツづ可堕ョツつウツづ按つ「ツ陳クツ点ツづ個つ、ツつソXツつゥツづァツづ個陛督づ個コツスツトツつェツ催渉ャツづ可づ按づゥツ点ツづーツ探ツつキ
		for(int u = 0; u < V; u++){
			if(!used[u] && (v == -1 || mincost[u] < mincost[v])){
				v = u;
			}
		}
		if(v == -1)
			break;
		used[v] = true;
		res += mincost[v];
		
		for(int u = 0; u < V; u++){
			mincost[u] = min(mincost[u],cost[v][u]);
		}
	}
	return res;
}


int main(){

	int n;
	while(cin>>n&&n!=0){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cost[i][j]=INF;
			}
		}
		V=n;
		vector<Circle> vc;
		for(int i = 0; i < n; i++){
			Circle c;
			cin>>c.x>>c.y>>c.z>>c.r;
			vc.push_back(c);
		}
		UnionFindTree uft(n);
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(i==j)
					continue;
				double dist=(vc[i].x-vc[j].x)*(vc[i].x-vc[j].x)
					+(vc[i].y-vc[j].y)*(vc[i].y-vc[j].y)
					+(vc[i].z-vc[j].z)*(vc[i].z-vc[j].z);
				// ツ重ツづ按づづつ「ツづゥ
				if(EQ(dist,(vc[i].r+vc[j].r)*(vc[i].r+vc[j].r))||(dist<(vc[i].r+vc[j].r)*(vc[i].r+vc[j].r))){
					uft.unite(i,j);
					break;
				}
			}
		}
		// ツ重ツづ按づづつ「ツづゥツづÍRXg0Ìm[hð£ÁÄ¨­
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(i==j)
					continue;
				if(uft.same(i,j)){
					cost[i][j]=0;
				}
				else{
					double dist=sqrt((vc[i].x-vc[j].x)*(vc[i].x-vc[j].x)
						+(vc[i].y-vc[j].y)*(vc[i].y-vc[j].y)
						+(vc[i].z-vc[j].z)*(vc[i].z-vc[j].z));
					cost[i][j]=dist-(vc[i].r+vc[j].r);
				}
			}
		}
		double res=prim();
		printf("%.5f\n",res);
	}


	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:164:53: error: 'sqrt' was not declared in this scope
  164 |                                         double dist=sqrt((vc[i].x-vc[j].x)*(vc[i].x-vc[j].x)
      |                                                     ^~~~