Language: C++

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

const int mxN = 1e5;
vt<ar<int, 3>> E;
int link[mxN], size[mxN];

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

bool same(int a, int b) {
    return find(a) == find(b);
}

void unite(int a, int b) {
    a = find(a);
    b = find(b);
    
    if (size[a] < size[b]) swap(a, b);
    
    size[a] += size[b];
    link[b] = a;
}

void solve() {
    int n;
    read(n);
    
    vt<ar<int, 2>> xv, yv;
    
    map<ar<int, 2>, int> mp;
    FOR(n) {
        int x, y;
        read(x, y);
        mp[{x, y}] = i;
        xv.pb({x, y});
        yv.pb({y, x});
    }
    
    sort(all(xv));
    sort(all(yv));
    
    FOR(i, 1, n) {
        int x = abs(xv[i][0] - xv[i - 1][0]);
        int y = mp[{xv[i - 1][0], xv[i - 1][1]}];
        int z = mp[{xv[i][0], xv[i][1]}];
        E.pb({x, y, z});
        x = abs(yv[i][0] - yv[i - 1][0]);
        y = mp[{yv[i - 1][1], yv[i - 1][0]}];
        z = mp[{yv[i][1], yv[i][0]}];
        E.pb({x, y, z});
    }
    
    sort(all(E));
    FOR(n) {
        link[i] = i;
        size[i] = 1;
    }
    
    int ans = 0;
    EACH(x, E) {
        if (!same(x[1], x[2])) {
            ans += x[0];
            unite(x[1], x[2]);
        }
    }
    
    print(ans);
    
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
        //write("Case #", i + 1, ": ");
        solve();
        
    }
    
}



Compiler output:
a.cc:149:13: error: 'long long int link [100000]' redeclared as different kind of entity
  149 | int link[mxN], size[mxN];
      |             ^
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:1:
/usr/include/unistd.h:819:12: note: previous declaration 'int link(const char*, const char*)'
  819 | extern int link (const char *__from, const char *__to)
      |            ^~~~
a.cc: In function 'long long int find(long long int)':
a.cc:152:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  152 |     if (link[x] == x) {
      |               ^
a.cc:152:17: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  152 |     if (link[x] == x) {
      |         ~~~~~~~~^~~~
a.cc:155:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  155 |     return find(link[x]);
      |                       ^
a.cc:155:16: error: no matching function for call to 'find(int (&)(const char*, const char*) noexcept)'
  155 |     return find(link[x]);
      |            ~~~~^~~~~~~~~
a.cc:151:5: note: candidate: 'long long int find(long long int)' (near match)
  151 | int find(int x) {
      |     ^~~~
a.cc:151:5: note:   conversion of argument 1 would be ill-formed:
a.cc:155:23: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'long long int' [-fpermissive]
  155 |     return find(link[x]);
      |                 ~~~~~~^
      |                       |
      |                       int (*)(const char*, const char*) noexcept
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:   candidate expects 4 arguments, 1 provided
In file included from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   candidate expects 3 arguments, 1 provided
a.cc: In function 'void unite(long long int, long long int)':
a.cc:166:9: error: reference to 'size' is ambiguous
  166 |     if (size[a] < size[b]) swap(a, b);
      |         ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:149:16: note:                 'long long int size [100000]'
  149 | int link[mxN], size[mxN];
      |                ^~~~
a.cc:166:19: error: reference to 'size' is ambiguous
  166 |     if (size[a] < size[b]) swap(a, b);
      |                   ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:149:16: note:                 'long long int size [100000]'
  149 | int link[mxN], size[mxN];
      |                ^~~~
a.cc:168:5: error: reference to 'size' is ambiguous
  168 |     size[a] += size[b];
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:149:16: note:                 'long long int size [100000]'
  149 | int link[mxN], size[mxN];
      |                ^~~~
a.cc:168:16: error: reference to 'size' is ambiguous
  168 |     size[a] += size[b];
      |                ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:149:16: note:                 'long long int size [100000]'
  149 | int link[mxN], size[mxN];
      |                ^~~~
a.cc:169:11: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  169 |     link[b] = a;
      |           ^
a.cc:169:13: error: assignment of read-only location '*(link + ((sizetype)b))'
  169 |     link[b] = a;
      |     ~~~~~~~~^~~
a.cc: In function 'void solve()':
a.cc:203:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  203 |         link[i] = i;
      |               ^
a.cc:203:17: error: assignment of read-only location '*(link + ((sizetype)i))'
  203 |         link[i] = i;
      |         ~~~~~~~~^~~
a.cc:204:9: error: reference to 'size' is ambiguous
  204 |         size[i] = 1;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:149:16: note:                 'long long int size [100000]'
  149 | int link[mxN], size[mxN];
      |                ^~~~