Language: C++

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>

typedef long long ll;

const ll INF=1E9+10;
const ll MAXN=1e5+10;
using namespace std;

int par[2*MAXN]; 

struct NODE{
	ll len,a,b;
}node[2*MAXN];

struct NO{
	ll sit,order;
}x[MAXN],y[MAXN];

ll rank[MAXN];

bool cmp1(NO i,NO j){
	return i.sit<j.sit;
}
bool cmp2(NODE h,NODE k){
	return h.len<k.len;
}

void init(int v){//初始化集合 
	for(int i=1;i<=v;i++){
		rank[i]=i;//最开始第i个顶点的集合是他自己 
	}
} 
void unit(ll a,ll b){//合并集合 
	rank[a]=b;//a的前驱改为b 
}

ll find(ll a){//寻找根节点 
	if(rank[a]==a)	return a;
	else return find(rank[a]); 
} 
ll Kruskal(ll ver,ll edge){//顶点数量、边数 
	ll tot=0,e=0;//目前的权值和已加入的边数
	
	for(int i=1;i<=edge&&e<ver-1;i++){
		ll h=find(node[i].a);
		ll k=find(node[i].b);
		if(h!=k){//如果这两个点不在同一个集合中，说明可以加入这条边 
			tot+=node[i].len;//增加权值 
			e++;//增加边数 
			unit(h,k); //合并这两个点到同一个集合 
		}
	}
	 
	return tot; 
}

 int main() {
 	ll n;
 	scanf("%lld",&n);
 	for(int i=1;i<=n;i++){
 		cin>>x[i].sit>>y[i].sit; 	
 		x[i].order=i;
 		y[i].order=i;
	}
	sort(x+1,x+n+1,cmp1);
	sort(y+1,y+n+1,cmp1);
	 
	//一共有2*n-2条边从 1到2*n-2 
	for(int i=1;i<n;i++){
		node[i].len=x[i+1].sit-x[i].sit;
		node[i].a=x[i+1].order;node[i].b=x[i].order;
		
		node[i+n-1].len=y[i+1].sit-y[i].sit;
		node[i+n-1].a=y[i+1].order;node[i+n-1].b=y[i].order;
	}
	
	sort(node+1,node+2*n-1,cmp2);
	
	//克鲁斯卡尔算法 
	init(n); 
	ll ans=Kruskal(n,2*n-2);//顶点数量、边数 
	cout<<ans<<endl;
	
 	return 0;
 }

Compiler output:
a.cc: In function 'void init(int)':
a.cc:33:17: error: reference to 'rank' is ambiguous
   33 |                 rank[i]=i;//最开始第i个顶点的集合是他自己
      |                 ^~~~
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:2:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:22:4: note:                 'll rank [100010]'
   22 | ll rank[MAXN];
      |    ^~~~
a.cc: In function 'void unit(ll, ll)':
a.cc:37:9: error: reference to 'rank' is ambiguous
   37 |         rank[a]=b;//a的前驱改为b
      |         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:22:4: note:                 'll rank [100010]'
   22 | ll rank[MAXN];
      |    ^~~~
a.cc: In function 'll find(ll)':
a.cc:41:12: error: reference to 'rank' is ambiguous
   41 |         if(rank[a]==a)  return a;
      |            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:22:4: note:                 'll rank [100010]'
   22 | ll rank[MAXN];
      |    ^~~~
a.cc:42:26: error: reference to 'rank' is ambiguous
   42 |         else return find(rank[a]);
      |                          ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:22:4: note:                 'll rank [100010]'
   22 | ll rank[MAXN];
      |    ^~~~