Language: C++

#include<bits/stdc++.h>
using namespace std;

const int MAX_N = 100001;
struct edge {int u,v,cost;};
typedef struct edge edge;
vector<edge> es;
bool comp(const edge& e1,const edge& e2){
  return e1.cost<e2.cost;
}

bool comp1(pair<int,int> p1,pair<int,int> p2){
  return p1.first<p2.first;
}

bool comp2(pair<int,int> p1,pair<int,int> p2){
  return p1.second<p2.second;
}
int par[MAX_N];
int rank[MAX_N];
void init (int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=0;
  }
}

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

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;
  if(rank[x]<rank[y]){
    par[x] = y;
  }else{
    par[y]=x;
    if(rank[x] == rank[y]) rank[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}

int kruskal(int V,int E){
  sort(es.begin(),es.end(),comp);
  init(V);
  int res=0;
  for(int i=0;i<E;i++){
    edge e=es[i];
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res += e.cost;
    }
  }
  return res;
}
int main (){
  int n;
  cin >> n;
  vector<pair<int,int> > xy;
  for(int i=0;i<n;i++){
    int t1,t2;
    cin >> t1 >> t2 ;
    xy.push_back(make_pair(t1,t2));
  }
  sort(xy.begin(),xy.end(),comp1);

  for(int i=0;i<n;i++){
    int p,next;
    p=i-1;
    next=i+1;
    if(p>=0){
      edge t1;
      t1.u = p;
      t1.v = i;
      t1.cost = abs(xy[i].first-xy[p].first);
      es.push_back(t1);
    }
    if(next<n){
      edge t;
      t.u = i;
      t.v = next;
      t.cost = abs(xy[i].first-xy[next].first);
      es.push_back(t);
    }
  }
  sort(xy.begin(),xy.end(),comp2);

  for(int i=0;i<n;i++){
    cout<<xy[i].first<<" "<<xy[i].second<<endl;
  }
  
  for(int i=0;i<n;i++){
    int p,next;
    p=i-1;
    next=i+1;
    if(p>=0){
      edge t;
      t.u = p;
      t.v = i;
      t.cost = abs(xy[i].second-xy[p].second);
      es.push_back(t);
    }
    if(next<n){
      edge t;
      t.u = i;
      t.v = next;
      t.cost = abs(xy[i].second-xy[next].second);
      es.push_back(t);
    }
  }
  //cout<<es.size()<<endl;
  //V = n;
  //E = ((n-2)*2+2)*2;
  cout<<kruskal(n,es.size())<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:24:5: error: reference to 'rank' is ambiguous
   24 |     rank[i]=0;
      |     ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:20:5: note:                 'int rank [100001]'
   20 | int rank[MAX_N];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:40:6: error: reference to 'rank' is ambiguous
   40 |   if(rank[x]<rank[y]){
      |      ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [100001]'
   20 | int rank[MAX_N];
      |     ^~~~
a.cc:40:14: error: reference to 'rank' is ambiguous
   40 |   if(rank[x]<rank[y]){
      |              ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [100001]'
   20 | int rank[MAX_N];
      |     ^~~~
a.cc:44:8: error: reference to 'rank' is ambiguous
   44 |     if(rank[x] == rank[y]) rank[x]++;
      |        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [100001]'
   20 | int rank[MAX_N];
      |     ^~~~
a.cc:44:19: error: reference to 'rank' is ambiguous
   44 |     if(rank[x] == rank[y]) rank[x]++;
      |                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [100001]'
   20 | int rank[MAX_N];
      |     ^~~~
a.cc:44:28: error: reference to 'rank' is ambiguous
   44 |     if(rank[x] == rank[y]) rank[x]++;
      |                            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [100001]'
   20 | int rank[MAX_N];
      |     ^~~~