Language: C++

#include <bits/stdc++.h>
typedef long long LL;
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second

using namespace std;

VI ps;

int findp(int i){
	if (ps[i]!=i) ps[i]=findp(ps[i]);
	return ps[i];
}

void merge(int i,int j){
	ps[findp(i)]=ps[findp(j)];
}

int main(){
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    VI cols(1e5+1,-1);
    VI rows(1e5+1,-1);
    ps=VI(n);
    REP(i,n){
		ps[i]=i;
	}
	VPII points;
    REP(i,n){
		DRI(x,y);
		points.PB({x,y});
		if (cols[y]!=-1) {merge(i,cols[y]);}
		if (rows[x]!=-1) {merge(i,rows[x]);}
		cols[y]=i;
		rows[x]=i;
	}
	vector<set<int>> nbc(n);
	vector<set<int>> nbr(n);
	REP(i,n){
		int p=findp(i);
		nbr[p].add(points[i].F);
		nbc[p].add(points[i].S);
		}
	LL rr=0;
	REP(i,n){
		int b=nbr[i].size;
		int c=nbr[i].size;
		rr+=(LL)b*c;
	}
	printf("%lld\n",rr-n);
}


Compiler output:
a.cc:54:24: error: macro "DRI" passed 2 arguments, but takes just 1
   54 |                 DRI(x,y);
      |                        ^
a.cc:10:9: note: macro "DRI" defined here
   10 | #define DRI(X) int (X); scanf("%d", &X)
      |         ^~~
a.cc: In function 'int main()':
a.cc:54:17: error: 'DRI' was not declared in this scope
   54 |                 DRI(x,y);
      |                 ^~~
a.cc:55:28: error: 'x' was not declared in this scope
   55 |                 points.PB({x,y});
      |                            ^
a.cc:55:30: error: 'y' was not declared in this scope
   55 |                 points.PB({x,y});
      |                              ^
a.cc:55:26: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   55 |                 points.PB({x,y});
      |                 ~~~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<int, int> >::value_type&' {aka 'const std::pair<int, int>&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:65:24: error: '__gnu_cxx::__alloc_traits<std::allocator<std::set<int> >, std::set<int> >::value_type' {aka 'class std::set<int>'} has no member named 'add'
   65 |                 nbr[p].add(points[i].F);
      |                        ^~~
a.cc:66:24: error: '__gnu_cxx::__alloc_traits<std::allocator<std::set<int> >, std::set<int> >::value_type' {aka 'class std::set<int>'} has no member named 'add'
   66 |                 nbc[p].add(points[i].S);
      |                        ^~~
a.cc:70:30: error: cannot convert 'std::set<int>::size' from type 'std::set<int>::size_type (std::set<int>::)() const noexcept' {aka 'long unsigned int (std::set<int>::)() const noexcept'} to type 'int'
   70 |                 int b=nbr[i].size;
      |                              ^~~~
a.cc:71:30: error: cannot convert 'std::set<int>::size' from type 'std::set<int>::size_type (std::set<int>::)() const noexcept' {aka 'long unsigned int (std::set<int>::)() const noexcept'} to type 'int'
   71 |                 int c=nbr[i].size;
      |                              ^~~~