Language: C++

//#include "pch.h"
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>

using namespace std;

/*-----------------------------------------------------------------------------
　ライブラリ
 -------------------------------------------------------------------------------*/
#if 0
// 3次元
vector<vector<vector<SDWORD>>> XXX(AAA, vector<vector<SDWORD>>(BBBB, vector<SDWORD>(CCC, -1)));
#endif

#if 0
// 2分探索
auto position = lower_bound(getValue.begin(), getValue.end(), 0);	// 0以上の要素位置を探す
int idx_lower = distance(getValue.begin(), position);				// 0以上の要素インデックス
int eraseNum = MIN(idx_lower, delCnt);								// 要素位置が個数になる
#endif

#if 0
// プライオリティーキュー、優先度
auto pqCmp = [](P a, P b) { return a.second > b.second; };
std::priority_queue<int, std::vector<int>, decltype(pqCmp)> que;
#endif


/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define MIN(a, b)				((a) < (b) ? a : b)
#define MAX(a, b)				((a) > (b) ? a : b)
#define CeilN(x, n)				(((((DWORD)(x))+((n)-1))/n)*n)	/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))					/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						

#define ArrayLength(x)			( sizeof( x ) / sizeof( x[ 0 ] ) )
#define	ArrayEnd(a)				(&(a)[ArrayLength(a)])			
#define	ArrayLast(a)			(&(a)[ArrayLength(a) - 1])		
#define MAX_DWORD				(0xFFFFFFFF)
#define	MAX_SDWORD				((SDWORD)0x7FFFFFFF)
#define	MIN_SDWORD				((SDWORD)0x80000000)
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979
#define deg_to_rad(deg)			(((deg)/360)*2*M_PI)
#define rad_to_deg(rad)			(((rad)/2/M_PI)*360)

#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
typedef short					SWORD;
typedef long					SDWORD;
typedef long long				SQWORD;
typedef unsigned short			WORD;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef pair<int, int> P;

/*-----------------------------------------------------------------------------
　パラメータ定義
 -------------------------------------------------------------------------------*/
#define N_MAX	(100)
#define K_MAX	(10)
#define M_MAX	(1000)
#define H_MAX	(1000)
#define W_MAX	(1000)
/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
struct edge {
	edge(int a, int b) {
		to = a;
		cost = b;
	}
	int to;
	int cost;
};

struct queInfo {
	queInfo(int a, int b) {
		idx = a;
		cost = b;
	}
	int idx;
	int cost;
};

bool cmpZahyou(P &a, P &b)
{
	return a.second < b.second;
}

// メイン
int main()
{
	int N;
	vector<P> zahyouX;
	vector<P> zahyouY;

	// 入力
	cin >> N;
	REP(i, N) {
		int x, y;
		cin >> x >> y;
		zahyouX.push_back(make_pair(i, x));
		zahyouY.push_back(make_pair(i, y));
	}

	// X方向のリスト
	static vector<edge> G[N_MAX];
	sort(zahyouX.begin(), zahyouX.end(), cmpZahyou);
	REP(i, N - 1) {
		int prevIdx = zahyouX[i].first;
		int nextIdx = zahyouX[i + 1].first;
		int kyori = zahyouX[i + 1].second - zahyouX[i].second;
		G[prevIdx].push_back(edge(nextIdx, kyori));
		G[nextIdx].push_back(edge(prevIdx, kyori));
	}

	// Y方向のリスト
	sort(zahyouY.begin(), zahyouY.end(), cmpZahyou);
	REP(i, N - 1) {
		int prevIdx = zahyouY[i].first;
		int nextIdx = zahyouY[i + 1].first;
		int kyori = zahyouY[i + 1].second - zahyouY[i].second;
		G[prevIdx].push_back(edge(nextIdx, kyori));
		G[nextIdx].push_back(edge(prevIdx, kyori));
	}

	// プライオリティーキュー（昇順、0,0から）
	auto pqCmp = [](queInfo a, queInfo b) { return a.cost > b.cost; };	// greaterがないので代わり
	priority_queue<queInfo, vector<queInfo>, decltype(pqCmp)> que;
	que.push(queInfo(0, 0));

	// プリム法
	QWORD ans = 0;
	vector<bool> isUsed(N, false);
	vector<DWORD> minCost(N, MAX_DWORD);
	while (!que.empty()) {
		// 一番小さいのからとれる
		queInfo point = que.top();
		que.pop();
		if (isUsed[point.idx]) {
			// すでに使用済み
			continue;
		}
		if (minCost[point.idx] < point.cost) {
			// もっと小さいのが入ってる
			continue;
		}

		// 頂点採用
		ans += point.cost;
		isUsed[point.idx] = true;

		for (auto egdeOne : G[point.idx]) {
			int nextCost = egdeOne.cost;
			if (minCost[egdeOne.to] > nextCost) {
				minCost[egdeOne.to] = nextCost;
				que.push(queInfo(egdeOne.to, nextCost));
			}
		}
	}

	cout << ans;
	cout << endl;
	return 0;
}


Compiler output:
a.cc:70:9: warning: "M_PI" redefined
   70 | #define M_PI                                    3.14159265358979
      |         ^~~~
In file included from /usr/include/c++/14/cmath:47,
                 from /usr/include/c++/14/math.h:36,
                 from a.cc:8:
/usr/include/math.h:1121:10: note: this is the location of the previous definition
 1121 | # define M_PI           3.14159265358979323846  /* pi */
      |          ^~~~
a.cc: In function 'int main()':
a.cc:157:67: error: no matching function for call to 'std::priority_queue<queInfo, std::vector<queInfo>, main()::<lambda(queInfo, queInfo)> >::priority_queue()'
  157 |         priority_queue<queInfo, vector<queInfo>, decltype(pqCmp)> que;
      |                                                                   ^~~
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_queue.h:691:9: note: candidate: 'template<class _InputIterator, class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, _Sequence&&, const _Alloc&) [with _Alloc = _InputIterator; _Requires = _Alloc; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  691 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:691:9: note:   candidate expects 5 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:679:9: note: candidate: 'template<class _InputIterator, class _Alloc, class, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, const _Sequence&, const _Alloc&) [with _Alloc = _InputIterator; <template-parameter-2-3> = _Alloc; _Requires = <template-parameter-1-3>; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  679 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:679:9: note:   candidate expects 5 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:671:9: note: candidate: 'template<class _InputIterator, class _Alloc, class, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, const _Alloc&) [with _Alloc = _InputIterator; <template-parameter-2-3> = _Alloc; _Requires = <template-parameter-1-3>; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  671 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:671:9: note:   candidate expects 4 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:663:9: note: candidate: 'template<class _InputIterator, class _Alloc, class, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Alloc&) [with _Alloc = _InputIterator; <template-parameter-2-3> = _Alloc; _Requires = <template-parameter-1-3>; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  663 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:663:9: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:649:9: note: candidate: 'template<class _InputIterator, class> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, _Sequence&&) [with <template-parameter-2-2> = _InputIterator; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  649 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:649:9: note:   candidate expects 4 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:638:9: note: candidate: 'template<class _InputIterator, class> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&, const _Sequence&) [with <template-parameter-2-2> = _InputIterator; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  638 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:638:9: note:   candidate expects 4 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:629:9: note: candidate: 'template<class _InputIterator, class> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(_InputIterator, _InputIterator, const _Compare&) [with <template-parameter-2-2> = _InputIterator; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  629 |         priority_queue(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:629:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:594:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(std::priority_queue<_Tp, _Sequence, _Compare>&&, const _Alloc&) [with _Requires = _Alloc; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  594 |         priority_queue(priority_queue&& __q, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:594:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:590:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const std::priority_queue<_Tp, _Sequence, _Compare>&, const _Alloc&) [with _Requires = _Alloc; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  590 |         priority_queue(const priority_queue& __q, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:590:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:585:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, _Sequence&&, const _Alloc&) [with _Requires = _Alloc; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  585 |         priority_queue(const _Compare& __x, _Sequence&& __c, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:585:9: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:579:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Sequence&, const _Alloc&) [with _Requires = _Alloc; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  579 |         priority_queue(const _Compare& __x, const _Sequence& __c,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:579:9: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:573:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Alloc&) [with _Requires = _Alloc; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  573 |         priority_queue(const _Compare& __x, const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:573:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:569:9: note: candidate: 'template<class _Alloc, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Alloc&) [with _Requires = _Alloc; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  569 |         priority_queue(const _Alloc& __a)
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:569:9: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_queue.h:554:9: note: candidate: 'template<class _Seq, class _Requires> std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue() [with _Requires = _Seq; _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  554 |         priority_queue()
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:554:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_queue.h:551:43: error: no type named 'type' in 'struct std::enable_if<false, void>'
  551 |       template<typename _Seq = _Sequence, typename _Requires = typename
      |                                           ^~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:563:7: note: candidate: 'std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, _Sequence&&) [with _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  563 |       priority_queue(const _Compare& __x, _Sequence&& __s = _Sequence())
      |       ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:563:7: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:558:7: note: candidate: 'std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Sequence&) [with _Tp = queInfo; _Sequence = std::vector<queInfo>; _Compare = main()::<lambda(queInfo, queInfo)>]'
  558 |       priority_queue(const _Compare& __x, const _Sequence& __s)
      |       ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:558:7: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_queue.h:496:11: note: candidate: 'std::priority_queue<queInfo, std::vector<queInfo>, main()::<lambda(queInfo, queInfo)> >::priority_queue(const std::priority_queue<queInfo, std::vector<queInfo>, main()::<lambda(queInfo, queInfo)> >&)'