Language: C++

#include <bits/stdc++.h>

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

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:18:5: error: reference to 'rank' is ambiguous
   18 |     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:11:5: note:                 'int rank [200002]'
   11 | int rank[200002];
      |     ^~~~
a.cc: In function 'void Union(int, int)':
a.cc:32:11: error: reference to 'rank' is ambiguous
   32 |   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:11:5: note:                 'int rank [200002]'
   11 | int rank[200002];
      |     ^~~~
a.cc:32:21: error: reference to 'rank' is ambiguous
   32 |   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:11:5: note:                 'int rank [200002]'
   11 | int rank[200002];
      |     ^~~~
a.cc:37:8: error: reference to 'rank' is ambiguous
   37 |     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:11:5: note:                 'int rank [200002]'
   11 | int rank[200002];
      |     ^~~~
a.cc:37:19: error: reference to 'rank' is ambiguous
   37 |     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:11:5: note:                 'int rank [200002]'
   11 | int rank[200002];
      |     ^~~~
a.cc:37:28: error: reference to 'rank' is ambiguous
   37 |     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:11:5: note:                 'int rank [200002]'
   11 | int rank[200002];
      |     ^~~~