Language: C++

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

constexpr int MAX_XY = 1e5;

struct UnionFind
{
    vector< int > data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = find(x), y = find(y);
        if(x == y) return(false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return(true);
    }

    int find(int k)
    {
        if(data[k] < 0) return(k);
        return(data[k] = find(data[k]));
    }

    int size(int k)
    {
        return(-data[find(k)]);
    }

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

int main() {
    int N; cin >> N;
    vector<tuple<int, int, int>> XY(N);
    // vector<int> X(MAX_XY + 1, 0);
    // vector<int> Y(MAX_XY + 1, 0);
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        XY[i] = tuple<int, int, int>(x, y, i);
        // X[x]++; Y[y]++;
    }
    UnionFind uf = UnionFind(N);
    sort(XY.begin(), XY.end(), less<tuple<int, int, int>>());
    for (int i = 0; i < N-1; i++) {
        if (get<0>(XY[i]) == get<0>(XY[i+1])) {
            uf.unite(get<2>(XY[i]), get<2>(XY[i+1]));
        }
    }
    for (int i = 0; i < N; i++) swap(get<0>(XY[i]), get<1>(XY[i])); // (y, x, i)
    sort(XY.begin(), XY.end(), less<tuple<int, int, int>>());
    for (int i = 0; i < N-1; i++) {
        if (get<0>(XY[i]) == get<0>(XY[i+1])) {
            uf.unite(get<2>(XY[i]), get<2>(XY[i+1]));
        }
    }
    for (int i = 0; i < N; i++) swap(get<0>(XY[i]), get<2>(XY[i])); // (i, x, y)
    sort(XY.begin(), XY.end(), less<tuple<int, int, int>>());
    map<int, set<int>> eachx;
    map<int, set<int>> eachy;
    for (int i = 0; i < N; i++) {
        eachx[uf.find(i)].insert(get<1>(XY[i]));
        eachy[uf.find(i)].insert(get<2>(XY[i]));
    }
    long long ans = 0;
    for (auto x : eachx) {
        int i = x.first;
        ans += max((long long)eachx[i].size() * eachy[i].size() - uf.size(i), (long long signed)0);
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:77:19: error: no matching function for call to 'max(long long unsigned int, long long int)'
   77 |         ans += max((long long)eachx[i].size() * eachy[i].size() - uf.size(i), (long long signed)0);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:77:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long long int')
   77 |         ans += max((long long)eachx[i].size() * eachy[i].size() - uf.size(i), (long long signed)0);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:77:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
   77 |         ans += max((long long)eachx[i].size() * eachy[i].size() - uf.size(i), (long long signed)0);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~