Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>

using namespace std;

struct UnionFind {
    vector<int> par;
    vector<int> sizes;

    UnionFind(int n) : par(n), sizes(n, 1) {
        for (int i = 0; i < n; i++) {
            par[i] = i;
        }
    }

    int find(int x) {
       if (x == par[x]) return x;
       return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sizes[find(x)];
    }
};

bool xord(pair< int, pair<int, int> > v1, pair< int, pair<int, int> >v2) {
    return v1.second.first < v2.second.first;
}
bool yord(pair< int, pair<int, int> > v1, pair< int, pair<int, int> >v2) {
    return v1.second.second < v2.second.second;
}

void solve(int n, vector< pair< int, pair<int, int> > > V) {
    vector< pair<int, pair <int, int> > > E;
    vector< pair<int, pair<int, int> > > V1 = V;
    vector< pair<int, pair<int, int> > > V2 = V;
    sort(V1.begin, V1.end, xord)
    sort(V2.begin, V2.end, yord)
    for (int i = 0; i < n-1; i++) {
        pair<int, pair <int, int> > = tmp;
        tmp.first = V1[i+1].second.first - V1[i].second.first;
        tmp.second.first = V1[i].first;
        tmp.second.second = V1[i+1].first;
        E.push_back(tmp);
    }
    for (int i = 0; i < n-1; i++) {
        pair<int, pair <int, int> > = tmp;
        tmp.first = V2[i+1].second.first - V2[i].second.first;
        tmp.second.first = V2[i].first;
        tmp.second.second = V2[i+1].first;
        E.push_back(tmp);
    }
    sort(E.begin(), E.end());
    int min_cost = 0;
    UnionFind uf(n);
    for (int i = 0; i < E.size(); i++) {
        if (!uf.same(E.second.first, E.second.second)) {
            min_cost += e.cost;
            uf.unite(E.second.first, E.second.second);
        }
    }
    std::cout << min_cost << std::endl;
}

int main() {
    struct timeval start,end;
    long long span;
    int n;

    gettimeofday(&start,NULL);

    std::cin >> n;
    vector< pair<int, pair<int, int> > > V(n);
    for (int i = 0; i < n; i++) {
        V[i].first = i;
        std::cin >> V[i].second.first >> V[i].second.second;
    }
    solve(n, V);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Compiler output:
a.cc: In function 'void solve(int, std::vector<std::pair<int, std::pair<int, int> > >)':
a.cc:56:9: error: no matching function for call to 'sort(<unresolved overloaded function type>, <unresolved overloaded function type>, bool (&)(std::pair<int, std::pair<int, int> >, std::pair<int, std::pair<int, int> >))'
   56 |     sort(V1.begin, V1.end, xord)
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:4762:5: note: candidate: 'template<class _RAIter> void std::sort(_RAIter, _RAIter)'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4762:5: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: candidate: 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note:   template argument deduction/substitution failed:
a.cc:56:9: note:   couldn't deduce template parameter '_RAIter'
   56 |     sort(V1.begin, V1.end, xord)
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note:   candidate expects 4 arguments, 3 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note:   template argument deduction/substitution failed:
a.cc:56:9: note:   couldn't deduce template parameter '_ExecutionPolicy'
   56 |     sort(V1.begin, V1.end, xord)
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:58:21: error: 'i' was not declared in this scope
   58 |     for (int i = 0; i < n-1; i++) {
      |                     ^
a.cc:66:37: error: expected unqualified-id before '=' token
   66 |         pair<int, pair <int, int> > = tmp;
      |                                     ^
a.cc:67:9: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   67 |         tmp.first = V2[i+1].second.first - V2[i].second.first;
      |         ^~~
      |         tm
a.cc:76:24: error: 'class std::vector<std::pair<int, std::pair<int, int> > >' has no member named 'second'
   76 |         if (!uf.same(E.second.first, E.second.second)) {
      |                        ^~~~~~
a.cc:76:40: error: 'class std::vector<std::pair<int, std::pair<int, int> > >' has no member named 'second'
   76 |         if (!uf.same(E.second.first, E.second.second)) {
      |                                        ^~~~~~
a.cc:77:25: error: 'e' was not declared in this scope
   77 |             min_cost += e.cost;
      |                         ^
a.cc:78:24: error: 'class std::vector<std::pair<int, std::pair<int, int> > >' has no member named 'second'
   78 |             uf.unite(E.second.first, E.second.second);
      |                        ^~~~~~
a.cc:78:40: error: 'class std::vector<std::pair<int, std::pair<int, int> > >' has no member named 'second'
   78 |             uf.unite(E.second.first, E.second.second);
      |                                        ^~~~~~