Language: C++

#include <bits/stdc++.h>
using namespace std;

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

#define MAX_V 100
#define INF INT_MAX

struct city
{
    int x, y, num;
};

int cost[100000][100000];
int mincost[100000];
bool used[100000];
int V;
int prim(){
    for(int i=0;i<V;i++){
        mincost[i]=INF;
        used[i]=false;
    }
    mincost[0]=0;
    int res=0;
    while(true){
        int v=-1;
        for(int u=0;u<V;u++){
            if(!used[u] && (v==-1 || mincost[u] <mincost[v] )) v=u;
        }
        if(v==-1) break;
        used[v]=true;
        res+=mincost[v];

        for(int u=0;u<V;u++){
            mincost[u]=min(mincost[u],cost[v][u]);
        } 
    }
    return res;
}
bool sortfirst(const city &left, const city &right)
{
    if (left.x == right.x)
    {
        if (left.y == right.y)
        {
            return left.num < right.num;
        }
        else
        {
            return left.y < right.y;
        }
    }
    else
    {
        return left.x < right.x;
    }
}

bool sortsecond(const city &left, const city &right)
{
    if (left.y == right.y)
    {
        if (left.x == right.x)
        {
            return left.num < right.num;
        }
        else
        {
            return left.x < right.x;
        }
    }
    else
    {
        return left.y < right.y;
    }
}

int main()
{
    int n;
    cin >> n;
    V=n;
    vector<city> v(n);
    rep(i, n)
    {
        cin >> v[i].x >> v[i].y ;
        v[i].num=i;
    }
    sort(v.begin(), v.end(), sortfirst);
    rep(i,n-1){
        cost[v[i].x][v[i].y]=min(v[i+1].x-v[1].x,v[i+1].y-v[1].y);
        cost[v[i].y][v[i].x]=cost[v[i].x][v[i].y];
    }
        sort(v.begin(), v.end(), sortsecond);
    rep(i,n-1){
        cost[v[i].x][v[i].y]=min(v[i+1].x-v[1].x,v[i+1].y-v[1].y);
        cost[v[i].y][v[i].x]=cost[v[i].x][v[i].y];
    }
    cout<<prim()<<endl;
}

Compiler output:
/tmp/ccBbkTzU.o: in function `prim()':
a.cc:(.text+0x21): relocation truncated to fit: R_X86_64_PC32 against symbol `mincost' defined in .bss section in /tmp/ccBbkTzU.o
a.cc:(.text+0x34): relocation truncated to fit: R_X86_64_PC32 against symbol `used' defined in .bss section in /tmp/ccBbkTzU.o
a.cc:(.text+0x42): relocation truncated to fit: R_X86_64_PC32 against symbol `V' defined in .bss section in /tmp/ccBbkTzU.o
a.cc:(.text+0x4d): relocation truncated to fit: R_X86_64_PC32 against symbol `mincost' defined in .bss section in /tmp/ccBbkTzU.o
a.cc:(.text+0x74): relocation truncated to fit: R_X86_64_PC32 against symbol `used' defined in .bss section in /tmp/ccBbkTzU.o
a.cc:(.text+0x99): relocation truncated to fit: R_X86_64_PC32 against symbol `mincost' defined in .bss section in /tmp/ccBbkTzU.o
a.cc:(.text+0xb0): relocation truncated to fit: R_X86_64_PC32 against symbol `mincost' defined in .bss section in /tmp/ccBbkTzU.o
a.cc:(.text+0xc7): relocation truncated to fit: R_X86_64_PC32 against symbol `V' defined in .bss section in /tmp/ccBbkTzU.o
a.cc:(.text+0xe2): relocation truncated to fit: R_X86_64_PC32 against symbol `used' defined in .bss section in /tmp/ccBbkTzU.o
a.cc:(.text+0xfa): relocation truncated to fit: R_X86_64_PC32 against symbol `mincost' defined in .bss section in /tmp/ccBbkTzU.o
a.cc:(.text+0x144): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status