Language: C++

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int par[10004];
int rank[10004];

void init(int n){
  rep(i,n){
    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);
}

signed main(){
  int n,q;
  cin>>n>>q;
  init(n);
  rep(i,q){
    int com,x,y;
    cin>>com>>x>>y;
    if(com){
      cout<<same(x,y)<<endl;
    }else{
      unite(x,y);
    }
  }
  return 0;
}

Compiler output:
a.cc: In function 'void init(long long int)':
a.cc:18:5: error: reference to 'rank' is ambiguous
   18 |     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:13:5: note:                 'long long int rank [10004]'
   13 | int rank[10004];
      |     ^~~~
a.cc: In function 'void unite(long long int, long long int)':
a.cc:31:6: error: reference to 'rank' is ambiguous
   31 |   if(rank[x]<rank[y])par[x]=y;
      |      ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'long long int rank [10004]'
   13 | int rank[10004];
      |     ^~~~
a.cc:31:14: error: reference to 'rank' is ambiguous
   31 |   if(rank[x]<rank[y])par[x]=y;
      |              ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'long long int rank [10004]'
   13 | int rank[10004];
      |     ^~~~
a.cc:34:8: error: reference to 'rank' is ambiguous
   34 |     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:13:5: note:                 'long long int rank [10004]'
   13 | int rank[10004];
      |     ^~~~
a.cc:34:17: error: reference to 'rank' is ambiguous
   34 |     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:13:5: note:                 'long long int rank [10004]'
   13 | int rank[10004];
      |     ^~~~
a.cc:34:25: error: reference to 'rank' is ambiguous
   34 |     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:13:5: note:                 'long long int rank [10004]'
   13 | int rank[10004];
      |     ^~~~