Language: C++

#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_V 100
#define MAX_E 10000
 
int V,E,par[MAX_V],rank[MAX_V];
 
struct Colony{
    double x,y,z,r;
    Colony(){}
    Colony(double x,double y,double z,double r) : x(x),y(y),z(z),r(r) {}
};
 
struct Edge{
    int u,v;
    double dist;
    Edge(){}
    Edge(int u,int v,double dist) : u(u),v(v),dist(dist) {}
};
 
bool comp(const Edge &e1,const Edge &e2){
    return e1.dist < e2.dist;
}
 
Edge es[MAX_E];
 
void init(){
    for(int i = 0 ; i < V ; i++){
	par[i] = i;
	rank[i] = 0;
    }
}
 
int find(int x){
    if(par[x] == x){
	return x;
    }
    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[x] == rank[y]){
	    rank[x]++;
	}
    }
}
 
bool same(int x,int y){
    return find(x) == find(y);
}
 
double kruskal(){
    sort(es,es+E,comp);
    init();
    double res = 0.0;
    for(int i = 0 ; i < E ; i++){
	Edge e = es[i];
	if(!same(e.u,e.v)){
	    unite(e.u,e.v);
	    res += e.dist;
	}
    }
    return res;
}
 
double getDist(const Colony &c1,const Colony &c2){
    return sqrt(pow(c1.x-c2.x,2)+pow(c1.y-c2.y,2)+pow(c1.z-c2.z,2))-c1.r-c2.r;
}
 
int main(){
    while(cin >> V,V){
	E = 0;
	double x,y,z,r;
	Colony C[MAX_V];
	for(int i = 0 ; i < V ; i++){
	    cin >> x >> y >> z >> r;
	    C[i] = Colony(x,y,z,r);
	}
     
	for(int i = 0 ; i < V ; i++){
	    for(int j = i+1 ; j < V ; j++){
		double dist = getDist(C[i],C[j]);
		es[E++] = Edge(i,j,max(dist,0.0));
	    }
	}
	printf("%.3f\n",kruskal());
    }
    return 0;
}

Compiler output:
a.cc: In function 'void init()':
a.cc:32:9: error: reference to 'rank' is ambiguous
   32 |         rank[i] = 0;
      |         ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:20: note:                 'int rank [100]'
    8 | int V,E,par[MAX_V],rank[MAX_V];
      |                    ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:49:8: error: reference to 'rank' is ambiguous
   49 |     if(rank[x] < rank[y]){
      |        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:20: note:                 'int rank [100]'
    8 | int V,E,par[MAX_V],rank[MAX_V];
      |                    ^~~~
a.cc:49:18: error: reference to 'rank' is ambiguous
   49 |     if(rank[x] < rank[y]){
      |                  ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:20: note:                 'int rank [100]'
    8 | int V,E,par[MAX_V],rank[MAX_V];
      |                    ^~~~
a.cc:53:12: error: reference to 'rank' is ambiguous
   53 |         if(rank[x] == rank[y]){
      |            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:20: note:                 'int rank [100]'
    8 | int V,E,par[MAX_V],rank[MAX_V];
      |                    ^~~~
a.cc:53:23: error: reference to 'rank' is ambiguous
   53 |         if(rank[x] == rank[y]){
      |                       ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:20: note:                 'int rank [100]'
    8 | int V,E,par[MAX_V],rank[MAX_V];
      |                    ^~~~
a.cc:54:13: error: reference to 'rank' is ambiguous
   54 |             rank[x]++;
      |             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:20: note:                 'int rank [100]'
    8 | int V,E,par[MAX_V],rank[MAX_V];
      |                    ^~~~