Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

using vd=vector<double>;
using data=tuple<double,int,int>;

double hypot3(double x,double y,double z){
	return sqrt(x*x+y*y+z*z);
}
double dist(vd a, vd b){
	auto d=hypot3(a[0]-b[0],a[1]-b[1],a[2]-b[2]);
	return max(d-a[3]-b[3],0.0);
}

struct UnionFind{
	vi p;
	UnionFind(int s):p(s,-1){}
	void union(int a,int b){
		a=root(a);b=root(b);
		if(a!=b){
			if(p[b]<p[a])swap(a,b);
			p[a]+=p[b];p[b]=a;
		}
	}
	bool same(int a,int b){return root(a)==root(b);}
	int root(int a){return p[a]<0?a:p[a]=root(p[a]);}
};

int main(){
	int n;
	while(cin>>n,n){
		vector<vd> cell(n,vd(4));
		vector<data> edge;
		rep(i,n) {
			rep(j,4) cin>>cell[i][j];
			rep(j,i) edge.emplace_back(dist(cell[i],cell[j]),i,j);
		}
		sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});

		UnionFind uf(n);
		double ans=0;
		for(auto e:edge){
			double d; int a,b;
			tie(d,a,b)=e;
			if(!uf.same(a,b)){
				ans+=d;
				uf.unite(a,b);
			}
		}
		cout.precision(3);
		cout<<fixed<<ans<<endl;
	}
	return 0;
}



Compiler output:
a.cc:32:19: error: expected identifier before '(' token
   32 |         void union(int a,int b){
      |                   ^
a.cc:32:20: error: expected unqualified-id before 'int'
   32 |         void union(int a,int b){
      |                    ^~~
a.cc:32:20: error: expected ')' before 'int'
   32 |         void union(int a,int b){
      |                   ~^~~
      |                    )
a.cc: In function 'int main()':
a.cc:47:28: error: template argument 1 is invalid
   47 |                 vector<data> edge;
      |                            ^
a.cc:47:28: error: template argument 2 is invalid
a.cc:50:39: error: request for member 'emplace_back' in 'edge', which is of non-class type 'int'
   50 |                         rep(j,i) edge.emplace_back(dist(cell[i],cell[j]),i,j);
      |                                       ^~~~~~~~~~~~
a.cc:9:18: error: request for member 'begin' in 'edge', which is of non-class type 'int'
    9 | #define all(a) a.begin(),a.end()
      |                  ^~~~~
a.cc:52:22: note: in expansion of macro 'all'
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                      ^~~
a.cc:9:28: error: request for member 'end' in 'edge', which is of non-class type 'int'
    9 | #define all(a) a.begin(),a.end()
      |                            ^~~
a.cc:52:22: note: in expansion of macro 'all'
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                      ^~~
a.cc:52:35: error: reference to 'data' is ambiguous
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                   ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:19:7: note:                 'using data = class std::tuple<double, int, int>'
   19 | using data=tuple<double,int,int>;
      |       ^~~~
a.cc:52:35: error: 'data' has not been declared
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                   ^~~~
a.cc:52:42: error: reference to 'data' is ambiguous
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                          ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:19:7: note:                 'using data = class std::tuple<double, int, int>'
   19 | using data=tuple<double,int,int>;
      |       ^~~~
a.cc:52:42: error: 'data' has not been declared
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                          ^~~~
a.cc: In lambda function:
a.cc:52:63: error: no matching function for call to 'get<0>(int&)'
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                                         ~~~~~~^~~
In file included 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:
/usr/include/c++/14/bits/stl_pair.h:1250:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(pair<_Tp1, _Tp2>&)'
 1250 |     get(pair<_Tp1, _Tp2>& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1250:5: note:   template argument deduction/substitution failed:
a.cc:52:63: note:   mismatched types 'std::pair<_Tp1, _Tp2>' and 'int'
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                                         ~~~~~~^~~
/usr/include/c++/14/bits/stl_pair.h:1255:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(pair<_Tp1, _Tp2>&&)'
 1255 |     get(pair<_Tp1, _Tp2>&& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1255:5: note:   template argument deduction/substitution failed:
a.cc:52:63: note:   mismatched types 'std::pair<_Tp1, _Tp2>' and 'int'
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                                         ~~~~~~^~~
/usr/include/c++/14/bits/stl_pair.h:1260:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(const pair<_Tp1, _Tp2>&)'
 1260 |     get(const pair<_Tp1, _Tp2>& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1260:5: note:   template argument deduction/substitution failed:
a.cc:52:63: note:   mismatched types 'const std::pair<_Tp1, _Tp2>' and 'int'
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                                         ~~~~~~^~~
/usr/include/c++/14/bits/stl_pair.h:1265:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(const pair<_Tp1, _Tp2>&&)'
 1265 |     get(const pair<_Tp1, _Tp2>&& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1265:5: note:   template argument deduction/substitution failed:
a.cc:52:63: note:   mismatched types 'const std::pair<_Tp1, _Tp2>' and 'int'
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                                         ~~~~~~^~~
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/tuple:2445:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(tuple<_Elements ...>&)'
 2445 |     get(tuple<_Elements...>& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2445:5: note:   template argument deduction/substitution failed:
a.cc:52:63: note:   mismatched types 'std::tuple<_Elements ...>' and 'int'
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                                         ~~~~~~^~~
/usr/include/c++/14/tuple:2451:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(const tuple<_Elements ...>&)'
 2451 |     get(const tuple<_Elements...>& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2451:5: note:   template argument deduction/substitution failed:
a.cc:52:63: note:   mismatched types 'const std::tuple<_Elements ...>' and 'int'
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                                         ~~~~~~^~~
/usr/include/c++/14/tuple:2457:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(tuple<_Elements ...>&&)'
 2457 |     get(tuple<_Elements...>&& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2457:5: note:   template argument deduction/substitution failed:
a.cc:52:63: note:   mismatched types 'std::tuple<_Elements ...>' and 'int'
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                                         ~~~~~~^~~
/usr/include/c++/14/tuple:2466:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(const tuple<_Elements ...>&&)'
 2466 |     get(const tuple<_Elements...>&& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2466:5: note:   template argument deduction/substitution failed:
a.cc:52:63: note:   mismatched types 'const std::tuple<_Elements ...>' and 'int'
   52 |                 sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});
      |                                                         ~~~~~~^~~
In file included from /usr/include/c++/14/fu