Language: C++

#include <queue>
#include <vector>
#include <iostream>
using namespace std;
// ------ Class ------ //
class Graph2 {
public:
	// ------ Variables ------ //
	static const long double INF = 1000000000000000000.0L;
	int V, E; vector<vector<pair<int, long double> > > G;

	// ------ Constructors ------ //
	Graph2() : V(0), E(0), G(vector<vector<pair<int, long double> > >()) {}
	Graph2(int v) : V(v), E(0), G(vector<vector<pair<int, long double> > >(v)) {}
	Graph2(vector<vector<pair<int, long double> > > g) : V(g.size()), G(g) { for (int i = 0; i < g.size(); i++) E += g[i].size(); }

	// ------ Basic Functions ------ //
	int size() { return V; }
	void add1(int v1, int v2, long double w) { G[v1].push_back(make_pair(v2, w)); E++; }
	void add2(int v1, int v2, long double w) { add1(v1, v2, w); add1(v2, v1, w); }

	// ------ Operators ------ //
	bool operator==(const Graph2& g) const { return G == g.G; }
	bool operator!=(const Graph2& g) const { return G != g.G; }
	vector<pair<int, long double> > operator[](int x) { return G[x]; }

	// ------ Algorithms ------ //
	long double minspan() {
		vector<long double> d(V, INF);
		vector<bool> used(V, false);
		priority_queue<pair<long double, int> > que;
		for (int i = 0; i < V; i++) d[i] = INF;
		d[0] = 0; que.push(make_pair(0, 0));
		while (!que.empty()) {
			pair<long double, int> pa = que.top(); que.pop();
			int u = pa.second; used[u] = true;
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u][i].first;
				if (d[v] > G[u][i].second && !used[v]) {
					d[v] = G[u][i].second; que.push(make_pair(-d[v], v));
				}
			}
		}
		long double sum = 0;
		for (int i = 0; i < V; i++) sum += d[i];
		return sum;
	}
};
// ------ Main ------ //
int n; long double x[111], y[111], z[111], r[111];
int main() {
	while(cin >> n, n) {
		for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i] >> r[i];
		Graph2 G(n);
		for(int i = 0; i < n; i++) {
			for(int j = i + 1; j < n; j++) {
				long double dist = sqrtl((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j]));
				G.add2(i, j, (dist > r[i] + r[j]) ? (dist - r[i] - r[j]) : 0)
			}
		}
		cout << G.minspan() << endl;
	}
}

Compiler output:
a.cc:9:34: error: 'constexpr' needed for in-class initialization of static data member 'const long double Graph2::INF' of non-integral type [-fpermissive]
    9 |         static const long double INF = 1000000000000000000.0L;
      |                                  ^~~
a.cc: In function 'int main()':
a.cc:57:52: error: 'sqrtl' was not declared in this scope; did you mean 'strtol'?
   57 |                                 long double dist = sqrtl((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j]));
      |                                                    ^~~~~
      |                                                    strtol
a.cc:58:94: error: expected ';' before '}' token
   58 |                                 G.add2(i, j, (dist > r[i] + r[j]) ? (dist - r[i] - r[j]) : 0)
      |                                                                                              ^
      |                                                                                              ;
   59 |                         }
      |                         ~