Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<pair<int,pair<int,int> > >G;
int parent[1<<17],rank[1<<17];
pair<int,int>x[1<<17],y[1<<17];
int find(int a)
{
	return a!=parent[a]?parent[a]=find(parent[a]):a;
}
int unite(int a,int b)
{
	int pa=find(a),pb=find(b);
	if(rank[pa]<rank[pb])
	{
		parent[pb]=pa;
	}
	else
	{
		parent[pa]=pb;
		if(rank[pa]==rank[pb])rank[pb]++;
	}
}
main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		parent[i]=i;
		cin>>x[i].first>>y[i].first;
		x[i].second=y[i].second=i;
	}
	sort(x,x+n);
	sort(y,y+n);
	for(int i=0;i<n-1;i++)
	{
	G.push_back(make_pair(abs(x[i+1].first-x[i].first),make_pair(x[i].second,x[i+1].second)));
	G.push_back(make_pair(abs(y[i+1].first-y[i].first),make_pair(y[i].second,y[i+1].second)));
	}
	sort(G.begin(),G.end());
	long ans=0;
	for(int i=0;i<G.size();i++)
	{
		int nx=G[i].second.first,ny=G[i].second.second,cost=G[i].first;
		int px=find(nx),py=find(ny);
		if(px==py)continue;
		else
		{
			ans+=cost;
			unite(px,py);
		}
	}
	cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int unite(int, int)':
a.cc:15:12: error: reference to 'rank' is ambiguous
   15 |         if(rank[pa]<rank[pb])
      |            ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:6:19: note:                 'int rank [131072]'
    6 | int parent[1<<17],rank[1<<17];
      |                   ^~~~
a.cc:15:21: error: reference to 'rank' is ambiguous
   15 |         if(rank[pa]<rank[pb])
      |                     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:6:19: note:                 'int rank [131072]'
    6 | int parent[1<<17],rank[1<<17];
      |                   ^~~~
a.cc:22:20: error: reference to 'rank' is ambiguous
   22 |                 if(rank[pa]==rank[pb])rank[pb]++;
      |                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:6:19: note:                 'int rank [131072]'
    6 | int parent[1<<17],rank[1<<17];
      |                   ^~~~
a.cc:22:30: error: reference to 'rank' is ambiguous
   22 |                 if(rank[pa]==rank[pb])rank[pb]++;
      |                              ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:6:19: note:                 'int rank [131072]'
    6 | int parent[1<<17],rank[1<<17];
      |                   ^~~~
a.cc:22:39: error: reference to 'rank' is ambiguous
   22 |                 if(rank[pa]==rank[pb])rank[pb]++;
      |                                       ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:6:19: note:                 'int rank [131072]'
    6 | int parent[1<<17],rank[1<<17];
      |                   ^~~~
a.cc:24:1: warning: no return statement in function returning non-void [-Wreturn-type]
   24 | }
      | ^
a.cc: At global scope:
a.cc:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main()
      | ^~~~