Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int par1[200001], par2[200001];
int rank[200001];

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

void unite(int x, int y, int par[]) {
  x = find(x, par);
  y = find(y, par);
  if(x == y) return;

  if(rank[x] < rank[y]) {
    par[x] = y;
  }else {
    par[y] = x;
    if(rank[x] == rank[y]) rank[x]++;
  }
}

signed main() {
  int n, k, l;
  cin >> n >> k >> l;
  rep(i, 0, n + 1) {
    par1[i] = i;
    par2[i] = i;
  }
  rep(i, 0, k) {
    int a, b;
    cin >> a >> b;
    unite(a, b, par1);
  }
  rep(i, 0, l) {
    int a, b;
    cin >> a >> b;
    unite(a, b, par2);
  }
  vector<int> v;
  int s[200001] = {};
  int p[200001] = {};
  rep(i, 1, n + 1) {
    if(s[i]) continue;
    s[i] = 1;
    int c = 1;
    int vc = v.size();
    p[i] = vc;
    rep(j, i + 1, n + 1) {
      if((find(i, par1) == find(j, par1)) && (find(i, par2) == find(j, par2))) {
        s[j] = 1;
        p[j] = vc;
        c++;
      }
    }
    v.pb(c);
  }

  rep(i, 1, n + 1) {
    cout << v[p[i]] << " ";
  }
  cout << endl;
}


Compiler output:
a.cc: In function 'void unite(int, int, int*)':
a.cc:32:6: error: reference to 'rank' is ambiguous
   32 |   if(rank[x] < rank[y]) {
      |      ^~~~
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:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:32:16: error: reference to 'rank' is ambiguous
   32 |   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:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:36:8: error: reference to 'rank' is ambiguous
   36 |     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:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:36:19: error: reference to 'rank' is ambiguous
   36 |     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:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:36:28: error: reference to 'rank' is ambiguous
   36 |     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:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~