Language: C++

#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
typedef pair<int, int> P;
int x[100010], y[100010];
vector<int> X[100010], Y[100010];
bool visited[100010];
map<P, int> mp;
int ans = 0;

set<int> stX, stY;
set<P> st;
void search(int x, int y) {
    if (visited[mp[{x, y}]]) return;
    stX.insert(x);
    stY.insert(y);
    st.insert({x, y});
    visited[mp[{x, y}]] = true;
    for(auto to: Y[x]) {
        auto itr = mp.find({x, to});
        if (itr == mp.end()) continue; 
        search(x, to);
    }
    for(auto to: X[y]){
        auto itr = mp.find({x, to});
        if (itr == mp.end()) continue; 
        search(to, y);
    }
    
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, N)
        cin >> x[i] >> y[i];
        X[y[i]].push_back(x[i]);
        Y[x[i]].push_back(y[i]);
        mp[{x[i], y[i]}] = i;
    }
    int ans = 0;
    rep(i, N) {
        if (visited[i]) continue;
        search(x[i], y[i]);
        ans += stX.size() * stY.size() - st.size();
        st.clear();
        stX.clear();
        stY.clear();
    }

    cout<< ans << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:48:13: error: 'i' was not declared in this scope
   48 |         X[y[i]].push_back(x[i]);
      |             ^
a.cc:50:11: error: no match for 'operator[]' (operand types are 'std::map<std::pair<long long int, long long int>, long long int>' and '<brace-enclosed initializer list>')
   50 |         mp[{x[i], y[i]}] = i;
      |           ^
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::pair<long long int, long long int>; _Tp = long long int; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<const std::pair<long long int, long long int>, long long int> >; mapped_type = long long int; key_type = std::pair<long long int, long long int>]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::map<std::pair<long long int, long long int>, long long int>::key_type&' {aka 'const std::pair<long long int, long long int>&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::pair<long long int, long long int>; _Tp = long long int; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<const std::pair<long long int, long long int>, long long int> >; mapped_type = long long int; key_type = std::pair<long long int, long long int>]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::map<std::pair<long long int, long long int>, long long int>::key_type&&' {aka 'std::pair<long long int, long long int>&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc: At global scope:
a.cc:52:9: error: redefinition of 'long long int ans'
   52 |     int ans = 0;
      |         ^~~
a.cc:18:5: note: 'long long int ans' previously defined here
   18 | int ans = 0;
      |     ^~~
a.cc:4:18: error: expected unqualified-id before 'for'
    4 | #define rep(i,n) for( int i = 0; i < n; i++ )
      |                  ^~~
a.cc:53:5: note: in expansion of macro 'rep'
   53 |     rep(i, N) {
      |     ^~~
a.cc:53:9: error: 'i' does not name a type
   53 |     rep(i, N) {
      |         ^
a.cc:4:34: note: in definition of macro 'rep'
    4 | #define rep(i,n) for( int i = 0; i < n; i++ )
      |                                  ^
a.cc:53:9: error: 'i' does not name a type
   53 |     rep(i, N) {
      |         ^
a.cc:4:41: note: in definition of macro 'rep'
    4 | #define rep(i,n) for( int i = 0; i < n; i++ )
      |                                         ^
a.cc:62:5: error: 'cout' does not name a type
   62 |     cout<< ans << endl;
      |     ^~~~
a.cc:64:5: error: expected unqualified-id before 'return'
   64 |     return 0;
      |     ^~~~~~
a.cc:65:1: error: expected declaration before '}' token
   65 | }
      | ^