Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

int  n,q;
int par[10000];
int rank[10000];

void init(int n){
    REP(i,n){
        par[i]=i;
        rank[i]=0;
    }
    return;
}

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]++;
    }
    return;
}

bool same(int x,int y){
    return find(x)==find(y);
}
int main(){
  cin >> n >> q;
    init(n);
    REP(i,q){
        int com,x,y;
        cin >> com >> x >> y;
        if(com==1){
            if(same(x,y)) cout << 1 << endl;
            else cout << 0 << endl;
        }else{
            unite(x,y);
        }
    }
  return 0;
}

Compiler output:
a.cc: In function 'void init(int)':
a.cc:20:9: error: reference to 'rank' is ambiguous
   20 |         rank[i]=0;
      |         ^~~~
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:15:5: note:                 'int rank [10000]'
   15 | int rank[10000];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:37:8: error: reference to 'rank' is ambiguous
   37 |     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:15:5: note:                 'int rank [10000]'
   15 | int rank[10000];
      |     ^~~~
a.cc:37:16: error: reference to 'rank' is ambiguous
   37 |     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:15:5: note:                 'int rank [10000]'
   15 | int rank[10000];
      |     ^~~~
a.cc:41:12: error: reference to 'rank' is ambiguous
   41 |         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:15:5: note:                 'int rank [10000]'
   15 | int rank[10000];
      |     ^~~~
a.cc:41:21: error: reference to 'rank' is ambiguous
   41 |         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:15:5: note:                 'int rank [10000]'
   15 | int rank[10000];
      |     ^~~~
a.cc:41:30: error: reference to 'rank' is ambiguous
   41 |         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:15:5: note:                 'int rank [10000]'
   15 | int rank[10000];
      |     ^~~~