Language: C++

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double EPS = 1e-8, INF = 1e12, PI = acos(-1.0);
typedef complex<double> P;
namespace std{
	bool operator<(const P& a, const P& b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
inline double cross(const P& a, const P& b){ return imag(conj(a)*b); }
inline double dot(const P& a, const P& b){ return real(conj(a)*b); }
struct L : public vector<P>{
	L(const P &a, const P &b) {
		push_back(a); push_back(b);
	}
};
typedef vector<P> G;
inline int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if(cross(b, c) > EPS)   return +1;		// counter clockwise
	if(cross(b, c) <-EPS)   return -1;		// clockwise
	if(dot(b, c)   < EPS)     return +2;		// c--a--b on line
	if(norm(b)+EPS < norm(c)) return -2;		// a--b--c on line
	return 0;
}
bool intersectSP(const L &s, const P &p) {
	return ccw(p, s[0], s[1]) == 2;
	//return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}
P projection(const L &l, const P &p) {
  long double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}


int n, m, x, y, p[5000], q[5000];
bool use[5000];
double dist[5000], dd[5000][5000];

int main(){
	G g;
	cin >> n >> m >> x >> y; g.pb(P(x, y));
	rep(i, n){
		cin >> p[i] >> q[i];
		g.pb(P(p[i], q[i]));
	}
	n++;
	rep(i, n) rep(j, i) dd[i][j] = dd[j][i] = abs(g[i] - g[j]);
	
	double ans = 0;
	rep(i, n) dist[i] = dd[0][i];
	use[0] = 1;
	
	rep(it, m){
		double mn = INF; int mni;
		rep(i, n) if(!use[i]){
			if(dist[i] + EPS < mn){ mn = dist[i], mni = i; }
		}
		double mn2 = INF; int mni2;
		rep(i, n) if(use[i]){
			double d = dd[mni][i];
			if(d + EPS < mn2){ mn2 = d, mni2 = i; }
		}
		
		use[mni] = 1;
		rep(i, n) if(!use[i]){
			double d = distanceSP(L(g[mni], g[mni2]), g[i]);
			dist[i] = min(dist[i], d);
		}
		ans += dd[mni][mni2];
		/*
		cerr<<"taberu: "<<mni<<" from: "<<mni2<<endl;
		dbg(mn);*/
	}
	printf("%.9f\n", ans);
	
	return 0;
}

Compiler output:
a.cc: In function 'P projection(const L&, const P&)':
a.cc:45:18: error: no match for 'operator*' (operand types are 'long double' and 'std::complex<double>')
   45 |   return l[0] + t*(l[0]-l[1]);
      |                 ~^~~~~~~~~~~~
      |                 |      |
      |                 |      std::complex<double>
      |                 long double
In file included from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:1:
/usr/include/c++/14/complex:400:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const complex<_Tp>&)'
  400 |     operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:400:5: note:   template argument deduction/substitution failed:
a.cc:45:29: note:   mismatched types 'const std::complex<_Tp>' and 'long double'
   45 |   return l[0] + t*(l[0]-l[1]);
      |                             ^
/usr/include/c++/14/complex:409:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const _Tp&)'
  409 |     operator*(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:409:5: note:   template argument deduction/substitution failed:
a.cc:45:29: note:   mismatched types 'const std::complex<_Tp>' and 'long double'
   45 |   return l[0] + t*(l[0]-l[1]);
      |                             ^
/usr/include/c++/14/complex:418:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, const complex<_Tp>&)'
  418 |     operator*(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:418:5: note:   template argument deduction/substitution failed:
a.cc:45:29: note:   deduced conflicting types for parameter '_Tp' ('long double' and 'double')
   45 |   return l[0] + t*(l[0]-l[1]);
      |                             ^
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:45:29: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'long double'
   45 |   return l[0] + t*(l[0]-l[1]);
      |                             ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:45:29: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'long double'
   45 |   return l[0] + t*(l[0]-l[1]);
      |                             ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:45:29: note:   'std::complex<double>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   45 |   return l[0] + t*(l[0]-l[1]);
      |                             ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:45:29: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'long double'
   45 |   return l[0] + t*(l[0]-l[1]);
      |                             ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:45:29: note:   'std::complex<double>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   45 |   return l[0] + t*(l[0]-l[1]);
      |                             ^
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const valarray<_Tp>&, const valarray<_Tp>&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   template argument deduction/substitution failed:
a.cc:45:29: note:   mismatched types 'const std::valarray<_Tp>' and 'long double'
   45 |   return l[0] + t*(l[0]-l[1]);
      |                             ^
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const valarray<_Tp>&, const typename valarray<_Tp>::value_type&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   template argument deduction/substitution failed:
a.cc:45:29: note:   mismatched types 'const std::valarray<_Tp>' and 'long double'
   45 |   return l[0] + t*(l[0]-l[1]);
      |                             ^
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const typename valarray<_Tp>::value_type&, const valarray<_Tp>&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   template argument deduction/substitution failed:
a.cc:45:29: note:   'std::complex<double>' is not derived from 'const std::valarray<_Tp>'
   45 |   return l[0] + t*(l[0]-l[1]);
      |                             ^