Language: C++

#include<bits/stdc++.h>

using namespace std;

const int MAX_N=200000;

int par[MAX_N+1], par2[MAX_N+1];
int rank[MAX_N+1], rank2[MAX_N+1];

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

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

int find2(int x){
        if(par2[x]==x){
                return x;
        }
        else{
                return par2[x]=find2(par2[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]++;
        }
}

void unite2(int x, int y){
        x=find2(x);y=find2(y);
        if(x==y){
                return;
        }
        if(rank2[x]<rank2[y]){
                par2[x]=y;
        }
        else{
                par2[y]=x;
                if(rank2[x]==rank2[y])
                        rank2[x]++;
        }
}

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

bool same2(int x, int y){
        return find2(x)==find2(y);
}

int main(){
        int N, K, L;
        cin>>N>>K>>L;
        init(N);
        for(int i=0;i<K;i++){
                int p, q;
                cin>>p>>q;
                unite(p, q);
        }
        for(int i=0;i<L;i++){
                int r, s;
                cin>>r>>s;
                unite2(r, s);
        }
        for(int i=1;i<=N;i++){
                int cnt=0;
                for(int j=1;j<=N;j++){
                        if(same(i, j)&&same2(i, j)){
                                cnt++;
                        }
                }
                cout<<cnt;
                if(i!=N){
                        cout<<" ";
                }
                else{
                        cout<<endl;
                }
        }
        return 0;
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:13:17: 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:8:5: note:                 'int rank [200001]'
    8 | int rank[MAX_N+1], rank2[MAX_N+1];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:42:12: error: reference to 'rank' is ambiguous
   42 |         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:8:5: note:                 'int rank [200001]'
    8 | int rank[MAX_N+1], rank2[MAX_N+1];
      |     ^~~~
a.cc:42:20: error: reference to 'rank' is ambiguous
   42 |         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:8:5: note:                 'int rank [200001]'
    8 | int rank[MAX_N+1], rank2[MAX_N+1];
      |     ^~~~
a.cc:47:20: error: reference to 'rank' is ambiguous
   47 |                 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:8:5: note:                 'int rank [200001]'
    8 | int rank[MAX_N+1], rank2[MAX_N+1];
      |     ^~~~
a.cc:47:29: error: reference to 'rank' is ambiguous
   47 |                 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:8:5: note:                 'int rank [200001]'
    8 | int rank[MAX_N+1], rank2[MAX_N+1];
      |     ^~~~
a.cc:48:25: error: reference to 'rank' is ambiguous
   48 |                         rank[x]++;
      |                         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:5: note:                 'int rank [200001]'
    8 | int rank[MAX_N+1], rank2[MAX_N+1];
      |     ^~~~