Language: C++

#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

#define MAX_N 100000

class Node
{
    public:
        int x, y, index, cost = INT_MAX;;
        bool used = false;
};

int n;
int A[MAX_N][MAX_N] = {};
Node *nodes = new Node[MAX_N];

int prim()
{
    int i, u, v, minv, sum = 0;
    nodes[0].cost = 0;
    while (true) {
        u = -1; minv = INT_MAX;
        for (i = 0; i < n; i++) {
            if (nodes[i].cost < minv && !nodes[i].used) {
                u    = i;
                minv = nodes[i].cost;
            }
        }
        if (-1 == u) break;
        nodes[u].used = true;
        sum += nodes[u].cost;
        for (v = 0; v < n; v++) {
            if (!nodes[v].used && A[u][v] != 0) {
                nodes[v].cost = A[u][v] < nodes[v].cost ? A[u][v] : nodes[v].cost;
            }
        }
    }
    return sum;
}

bool xsort(Node a, Node b)
{
    if (a.x < b.x) return true;
    else return false;
}

bool ysort(Node a, Node b)
{
    if (a.y < b.y) return true;
    else return false;
}
void build_table()
{
    Node *xsorted = new Node[n];
    Node *ysorted = new Node[n];
    memcpy(xsorted, nodes, sizeof(Node) * n);
    memcpy(ysorted, nodes, sizeof(Node) * n);
    sort(xsorted, xsorted + n, xsort);
    sort(ysorted, ysorted + n, ysort);
/*
    cout << "xsorted:" << endl;
    for (int i = 0; i < n; i++) {
        cout << xsorted[i].x << " " << xsorted[i].y << endl;
    }
    cout << "ysorted:" << endl;
    for (int i = 0; i < n; i++) {
        cout << ysorted[i].x << " " << ysorted[i].y << endl;
    }
*/
    for (int i = 1; i < n - 1; i++) {
        A[xsorted[i].index][xsorted[i - 1].index] = A[xsorted[i].index][xsorted[i - 1].index] == 0 ? xsorted[i].x - xsorted[i - 1].x : min(xsorted[i].x - xsorted[i - 1].x, A[xsorted[i].index][xsorted[i - 1].index]);
        A[xsorted[i - 1].index][xsorted[i].index] = A[xsorted[i - 1].index][xsorted[i].index] == 0 ? xsorted[i].x - xsorted[i - 1].x : min(xsorted[i].x - xsorted[i - 1].x, A[xsorted[i - 1].index][xsorted[i].index]);
        A[xsorted[i + 1].index][xsorted[i].index] = A[xsorted[i + 1].index][xsorted[i].index] == 0 ? xsorted[i + 1].x - xsorted[i].x : min(xsorted[i + 1].x - xsorted[i].x, A[xsorted[i + 1].index][xsorted[i].index]);
        A[xsorted[i].index][xsorted[i + 1].index] = A[xsorted[i].index][xsorted[i + 1].index] == 0 ? xsorted[i + 1].x - xsorted[i].x : min(xsorted[i + 1].x - xsorted[i].x, A[xsorted[i].index][xsorted[i + 1].index]);
        A[ysorted[i].index][ysorted[i - 1].index] = A[ysorted[i].index][ysorted[i - 1].index] == 0 ? ysorted[i].y - ysorted[i - 1].y : min(ysorted[i].y - ysorted[i - 1].y, A[ysorted[i].index][ysorted[i - 1].index]);
        A[ysorted[i - 1].index][ysorted[i].index] = A[ysorted[i - 1].index][ysorted[i].index] == 0 ? ysorted[i].y - ysorted[i - 1].y : min(ysorted[i].y - ysorted[i - 1].y, A[ysorted[i - 1].index][ysorted[i].index]);
        A[ysorted[i + 1].index][ysorted[i].index] = A[ysorted[i + 1].index][ysorted[i].index] == 0 ? ysorted[i + 1].y - ysorted[i].y : min(ysorted[i + 1].y - ysorted[i].y, A[ysorted[i + 1].index][ysorted[i].index]);
        A[ysorted[i].index][ysorted[i + 1].index] = A[ysorted[i].index][ysorted[i + 1].index] == 0 ? ysorted[i + 1].y - ysorted[i].y : min(ysorted[i + 1].y - ysorted[i].y, A[ysorted[i].index][ysorted[i + 1].index]);
    }
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        nodes[i].index = i;
        cin >> nodes[i].x >> nodes[i].y;
    }
    build_table();
/*    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cout << " " << A[i][j];
      }
      cout << endl;
    }
*/
    cout << prim() << endl;
    return 0;
}

Compiler output:
a.cc:11:33: error: 'INT_MAX' was not declared in this scope
   11 |         int x, y, index, cost = INT_MAX;;
      |                                 ^~~~~~~
a.cc:4:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include <algorithm>
  +++ |+#include <climits>
    4 | using namespace std;
a.cc: In function 'int prim()':
a.cc:24:24: error: 'INT_MAX' was not declared in this scope
   24 |         u = -1; minv = INT_MAX;
      |                        ^~~~~~~
a.cc:24:24: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'