Language: C++

#include<bits/stdc++.h>

#define SORT(v) sort(v.begin(),v.end())
#define si(n) scanf("%d",&n)
#define sii(n,m) scanf("%d %d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld %lld",&n,&m)
#define ss(cad) scanf("%s",cad)
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl; 
#define M 1000000007
#define N_MAX 100010

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vp;

int link[100010], tam[100010], tam2[100010];
int visit[100010];

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

void unir(int a, int b){
	a = find(a);
	b = find(b);
	if(a == b)
		return;
	link[b] = a;
	tam[a] += tam[b];
	tam2[a] += tam2[b];
}

int main(){
	int n;
	si(n);
	vector<vi> grx, gry, cntx;
	grx.resize(100010);
	gry.resize(100010);
	cntx.resize(100010);
	for(int i = 0; i < n; i++){
		int a, b;
		sii(a, b);
		a--;
		b--;
		grx[a].push_back(b);
		gry[b].push_back(a);
	}

	for(int i = 0; i < 100000; i++){
		link[i] = i;
		if((int)gry[i].size() >= 2)
			tam[i] = 1;
		tam2[i] = 1;
	}

	for(int i = 0; i < 100000; i++){
		if((int)grx[i].size() >= 2)
			for(int p = 1; p < grx[i].size(); p++)
				//if((int)gry[grx[i][p-1]].size() >= 2 || (int)gry[grx[i][p]].size() >= 2)
					unir(grx[i][p-1], grx[i][p]);
	}
	for(int i = 0; i < 100000; i++){
		for(int p = 0; p < gry[i].size(); p++)
			cntx[find(i)].push_back(gry[i][p]);
	}
	for(int i = 0; i < 100000; i++){
		sort(cntx[i].begin(), cntx[i].end());
		cntx[i].resize(unique(cntx[i].begin(), cntx[i].end()) - cntx[i].begin());
	}
	ll ans = 0;
	for(int i = 0; i < 100000; i++){
		if(tam[find(i)] != 0)
			ans -= (ll)gry[i].size();
		if(visit[find(i)] == 0 && tam[find(i)] != 0){
			ans += (ll)tam2[find(i)]*(ll)cntx[find(i)].size();
			visit[find(i)] = 1;
			//printf("padre=%d, cnt=%d %lld\n", find(i), tam2[find(i)], ans);
		}
	}
	printf("%lld\n", ans);

	return 0;
}


Compiler output:
a.cc:25:16: error: 'int link [100010]' redeclared as different kind of entity
   25 | int link[100010], tam[100010], tam2[100010];
      |                ^
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 'int find(int)':
a.cc:29:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   29 |         if(x == link[x])        return x;
      |                       ^
a.cc:29:14: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   29 |         if(x == link[x])        return x;
      |            ~~^~~~~~~~~~
a.cc:30:22: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   30 |         return link[x] = find(link[x]);
      |                      ^
a.cc:30:37: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   30 |         return link[x] = find(link[x]);
      |                                     ^
a.cc:30:30: error: no matching function for call to 'find(int (&)(const char*, const char*) noexcept)'
   30 |         return link[x] = find(link[x]);
      |                          ~~~~^~~~~~~~~
a.cc:28:5: note: candidate: 'int find(int)' (near match)
   28 | int find(int x){
      |     ^~~~
a.cc:28:5: note:   conversion of argument 1 would be ill-formed:
a.cc:30:37: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'int' [-fpermissive]
   30 |         return link[x] = 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 unir(int, int)':
a.cc:38:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   38 |         link[b] = a;
      |               ^
a.cc:38:17: error: assignment of read-only location '*(link + ((sizetype)b))'
   38 |         link[b] = a;
      |         ~~~~~~~~^~~
a.cc: In function 'int main()':
a.cc:60:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |                 link[i] = i;
      |                       ^
a.cc:60:25: error: assignment of read-only location '*(link + ((sizetype)i))'
   60 |                 link[i] = i;
      |                 ~~~~~~~~^~~
a.cc:84:20: error: reference to 'visit' is ambiguous
   84 |                 if(visit[find(i)] == 0 && tam[find(i)] != 0){
      |                    ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:26:5: note:                 'int visit [100010]'
   26 | int visit[100010];
      |     ^~~~~
a.cc:86:25: error: reference to 'visit' is ambiguous
   86 |                         visit[find(i)] = 1;
      |                         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:26:5: note:                 'int visit [100010]'
   26 | int visit[100010];
      |     ^~~~~