Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define x first
#define y second
typedef pair <int, int> pi;

const int N = 1e5 + 10;
int n, u, v, v2, u2, ans, l, r, pa[N], sz[N];
vector <int> g[N];
pi p[N]; vector <pi> xx, yy;
struct edge { int u, v, w; };
bool operator < (edge a, edge b) { return a.w < b.w; }
vector <edge> e;

int root(int v) {
    return (pa[v] == v) ? v : pa[v] = root(pa[v]);
}

bool same(int u, int v) {
    return root(u) == root(v);
}

void merge(int u, int v) {
    u = root(u), v = root(v);
    if (u == v) return;
    if (sz[u] < sz[v]) swap(u, v);
    sz[u] += sz[v];
    pa[v] = u;
}

void kruskal() {
    for (int i = 0; i < n; ++i)
        pa[i] = i, sz[i] = 1;
    sort(e.begin(), e.end());
    for (auto i: e) {
        if (!same(i.u, i.v)) {
            merge(i.u, i.v);
            ans += i.w;
        }
    }
}

int f(int i, int j) {
    return min(abs(p[i].x - p[j].x), abs(p[i].y - p[j].y));
}

void make_graph() {
    for (int i = 0; i < n; ++i) {
        l = max(i - 3, 0ll), r = min(i + 3, n);
        v = xx[i].y;
        v2 = yy[i].y;
        for (int j = l; j < r; ++j) {
            u = xx[j].y;
            u2 = yy[j].y;
            if (v < u)
                e.push_back({v, u, f(v, u)});
            if (v2 < u2)
                e.push_back({v2, u2, f(v2, u2)});
        }
    }
}

main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p[i].x >> p[i].y;
        xx.push_back({p[i].x, i});
        yy.push_back({p[i].y, i});
    }
    sort(xx.begin(), xx.end());
    sort(yy.begin(), yy.end());
    make_graph();
    kruskal();
    cout << ans << '\n';
    return 0;
}


Compiler output:
a.cc: In function 'void make_graph()':
a.cc:50:16: error: no matching function for call to 'max(int64_t, long long int)'
   50 |         l = max(i - 3, 0ll), r = min(i + 3, n);
      |             ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:50:16: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   50 |         l = max(i - 3, 0ll), r = min(i + 3, n);
      |             ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:50:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   50 |         l = max(i - 3, 0ll), r = min(i + 3, n);
      |             ~~~^~~~~~~~~~~~
a.cc: At global scope:
a.cc:64:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   64 | main() {
      | ^~~~