Language: C++

#include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> P;
#define mp make_pair
#define RANK rank

map <P,int> ans;

int N, K, L;
int p[200002];
int rank[200002];
int A[200001];
int B[200001];

void init(int n) {
  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 x, int y) {
  int a = Find(x);
  int b = Find(y);
  if(a == b) return;
  
  else if(rank[a] > rank[b]) {
    p[a] = b;
  }
  else {
    p[b] = a;
    if(rank[a] == rank[b]) rank[b]++;
  }
  return;
}
    
int main() {
cin >> N >> K >> L;

  init(N);
  
  for(int i = 0; i < K; i++) {
    int p,q;
    cin >> p >> q;
    p--; q--;
    Union(p,q);
  }

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


  
  init(N);
  
  for(int i = 0; i < L; i++) {
    int r,s;
    cin >> r >> s;
    r--; s--;
    Union(r,s);
  }

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

  for(int i = 0; i < N; i++) {
    ans[mp(A[i],B[i])]++;
  }

  for(int i = 0; i < N; i++) {
    cout << ans[mp(A[i],B[i])] <<endl;
  }
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:19:5: error: reference to 'rank' is ambiguous
   19 |     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:12:5: note:                 'int rank [200002]'
   12 | int rank[200002];
      |     ^~~~
a.cc: In function 'void Union(int, int)':
a.cc:33:11: error: reference to 'rank' is ambiguous
   33 |   else if(rank[a] > rank[b]) {
      |           ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:5: note:                 'int rank [200002]'
   12 | int rank[200002];
      |     ^~~~
a.cc:33:21: error: reference to 'rank' is ambiguous
   33 |   else if(rank[a] > rank[b]) {
      |                     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:5: note:                 'int rank [200002]'
   12 | int rank[200002];
      |     ^~~~
a.cc:38:8: error: reference to 'rank' is ambiguous
   38 |     if(rank[a] == rank[b]) rank[b]++;
      |        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:5: note:                 'int rank [200002]'
   12 | int rank[200002];
      |     ^~~~
a.cc:38:19: error: reference to 'rank' is ambiguous
   38 |     if(rank[a] == rank[b]) rank[b]++;
      |                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:5: note:                 'int rank [200002]'
   12 | int rank[200002];
      |     ^~~~
a.cc:38:28: error: reference to 'rank' is ambiguous
   38 |     if(rank[a] == rank[b]) rank[b]++;
      |                            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:12:5: note:                 'int rank [200002]'
   12 | int rank[200002];
      |     ^~~~