Language: C++

//kruskal tree
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <cmath>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<double,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,j,k,m,n;
	double x,y,z;
	for(;cin>>n,n;){
		vector<tuple<double,double,double> >v;
		for(i=0;i<n;i++)cin>>x>>y>>z,v.push_back(make_tuple(x,y,z));
		for(m=i=0;i<n;i++)for(j=i+1;j<n;j++){
			for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
			a[m]=i,b[m]=j,node[m].first=x,node[m].second=m++;
		}
		sort(node,node+m);
		for(i=0;i<n;i++)parent[i]=i;
		for(x=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))x+=node[i].first;
		cout<<x<<endl;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:66: error: the value of 'k' is not usable in a constant expression
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                                  ^
a.cc:19:17: note: 'int k' is not const
   19 |         int i,j,k,m,n;
      |                 ^
a.cc:25:68: error: no matching function for call to 'get<k>(__gnu_cxx::__alloc_traits<std::allocator<std::tuple<double, double, double> >, std::tuple<double, double, double> >::value_type&)'
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                   ~~~~~~~~~~~~~~~~~^~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/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:25:68: error: the value of 'k' is not usable in a constant expression
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                   ~~~~~~~~~~~~~~~~~^~~~~~
a.cc:19:17: note: 'int k' is not const
   19 |         int i,j,k,m,n;
      |                 ^
a.cc:25:55: note: in template argument for type 'long unsigned int'
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                       ^~~~~~~~~~~~
/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:25:68: error: the value of 'k' is not usable in a constant expression
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                   ~~~~~~~~~~~~~~~~~^~~~~~
a.cc:19:17: note: 'int k' is not const
   19 |         int i,j,k,m,n;
      |                 ^
a.cc:25:55: note: in template argument for type 'long unsigned int'
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                       ^~~~~~~~~~~~
/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:25:68: error: the value of 'k' is not usable in a constant expression
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                   ~~~~~~~~~~~~~~~~~^~~~~~
a.cc:19:17: note: 'int k' is not const
   19 |         int i,j,k,m,n;
      |                 ^
a.cc:25:55: note: in template argument for type 'long unsigned int'
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                       ^~~~~~~~~~~~
/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:25:68: error: the value of 'k' is not usable in a constant expression
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                   ~~~~~~~~~~~~~~~~~^~~~~~
a.cc:19:17: note: 'int k' is not const
   19 |         int i,j,k,m,n;
      |                 ^
a.cc:25:55: note: in template argument for type 'long unsigned int'
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                       ^~~~~~~~~~~~
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:25:68: error: the value of 'k' is not usable in a constant expression
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                   ~~~~~~~~~~~~~~~~~^~~~~~
a.cc:19:17: note: 'int k' is not const
   19 |         int i,j,k,m,n;
      |                 ^
a.cc:25:55: note: in template argument for type 'long unsigned int'
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                       ^~~~~~~~~~~~
/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:25:68: error: the value of 'k' is not usable in a constant expression
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                   ~~~~~~~~~~~~~~~~~^~~~~~
a.cc:19:17: note: 'int k' is not const
   19 |         int i,j,k,m,n;
      |                 ^
a.cc:25:55: note: in template argument for type 'long unsigned int'
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                       ^~~~~~~~~~~~
/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:25:68: error: the value of 'k' is not usable in a constant expression
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                   ~~~~~~~~~~~~~~~~~^~~~~~
a.cc:19:17: note: 'int k' is not const
   19 |         int i,j,k,m,n;
      |                 ^
a.cc:25:55: note: in template argument for type 'long unsigned int'
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                       ^~~~~~~~~~~~
/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:25:68: error: the value of 'k' is not usable in a constant expression
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                   ~~~~~~~~~~~~~~~~~^~~~~~
a.cc:19:17: note: 'int k' is not const
   19 |         int i,j,k,m,n;
      |                 ^
a.cc:25:55: note: in template argument for type 'long unsigned int'
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                       ^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:138:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp& std::get(array<_Tp, _Nm>&)'
  138 |     get(array<_Tp, _Nm>&) noexcept;
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:138:5: note:   template argument deduction/substitution failed:
a.cc:25:68: error: the value of 'k' is not usable in a constant expression
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                   ~~~~~~~~~~~~~~~~~^~~~~~
a.cc:19:17: note: 'int k' is not const
   19 |         int i,j,k,m,n;
      |                 ^
a.cc:25:55: note: in template argument for type 'long unsigned int'
   25 |                         for(x=k=0;k<3;k++)x+=fabs(get<(const int)k>(v[i])-get<k>(v[j]));
      |                                                       ^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:142:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp&& std::get(array<_Tp, _Nm>&&)'
  142 |     get(array<_Tp, _Nm>&&) noexcep