Language: C++

#include <bits/stdc++.h>
#define ll long long
#define MAX_N 32
using namespace std;

int par[MAX_N];
int rank[MAX_N];
int n;

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        rank[i]=0;
    }
}

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

void unite(int x,int y){
    x = find2(x);
    y = find2(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 find2(x) == find2(y);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    init(n*2);
    int ans = 0;
    for(int i =0;i<n;i++){
        int a;
        cin>>a;
        for(int j = 0; j<a; j++){
            int t,s;
            cin>>t>>s;
            t--;
            if(s==1){
                if(same(i,t+n)&& same(i,t)){
                        
                }
                else{
                    ans++;
                    unite(i,t);
                }
            }else{
                if(same(i,t)  || same(i,t+n)){
                    break;
                }else{
                    unite(i,t+n);
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:13:9: error: reference to 'rank' is ambiguous
   13 |         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:7:5: note:                 'int rank [32]'
    7 | int rank[MAX_N];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:30:8: error: reference to 'rank' is ambiguous
   30 |     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:7:5: note:                 'int rank [32]'
    7 | int rank[MAX_N];
      |     ^~~~
a.cc:30:16: error: reference to 'rank' is ambiguous
   30 |     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:7:5: note:                 'int rank [32]'
    7 | int rank[MAX_N];
      |     ^~~~
a.cc:34:12: 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:7:5: note:                 'int rank [32]'
    7 | int rank[MAX_N];
      |     ^~~~
a.cc:34:21: 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:7:5: note:                 'int rank [32]'
    7 | int rank[MAX_N];
      |     ^~~~
a.cc:34:29: 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:7:5: note:                 'int rank [32]'
    7 | int rank[MAX_N];
      |     ^~~~