Language: C++

#include <bits/stdc++.h>

using namespace std;

int N,K,L;
int p[200001];
int rank[200001];
map <pair<int,int>,int> ans;
int a[200001];
int b[200001];

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

int Find (int x) {
  if(p[x] == x) return x;
  return p[x] = Find(p[x]);
}

void Union (int a, int b) {
  int x = Find(a);
  int y = Find(b);
  if(x == y) return;
  else {
    if(rank[x] > rank[y]) p[y] = x;
    else p[x] = y;
    if(rank[x] == rank[y]) rank[x]++;
  }
}
    
    
    
  

int main () {
  cin >> N >> K >> L;

  init();
  for(int i = 0; i < K; i++){
    int a,b;
    cin >> a >> b;
    a--; b--;
    Union(a,b);
  }

  for(int i = 0; i < N; i++) a[i] = Find(i);

  init();

  for(int i = 0; i < L; i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    Union(a,b);
  }

  for(int i = 0; i < N; i++) b[i] = Find(i);
 
  
  for(int i = 0; i < N; i++)  ans[make_pair(a[i],b[i])]++;

  for(int i = 0; i < N; i++)
    cout << ans[make_pair(a[i],b[i])] <<endl;
}
  

  


Compiler output:
a.cc: In function 'void init()':
a.cc:15:5: error: reference to 'rank' is ambiguous
   15 |     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 [200001]'
    7 | int rank[200001];
      |     ^~~~
a.cc: In function 'void Union(int, int)':
a.cc:29:8: error: reference to 'rank' is ambiguous
   29 |     if(rank[x] > rank[y]) p[y] = 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 [200001]'
    7 | int rank[200001];
      |     ^~~~
a.cc:29:18: error: reference to 'rank' is ambiguous
   29 |     if(rank[x] > rank[y]) p[y] = 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 [200001]'
    7 | int rank[200001];
      |     ^~~~
a.cc:31:8: error: reference to 'rank' is ambiguous
   31 |     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 [200001]'
    7 | int rank[200001];
      |     ^~~~
a.cc:31:19: error: reference to 'rank' is ambiguous
   31 |     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 [200001]'
    7 | int rank[200001];
      |     ^~~~
a.cc:31:28: error: reference to 'rank' is ambiguous
   31 |     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 [200001]'
    7 | int rank[200001];
      |     ^~~~