Language: C++

#include<cstdio>
#include<map>
#include<cstring>
#define mp make_pair
#define Maxn 200010
using namespace std;
typedef pair<int,int> pii;
int N,K,L;
map<pii,int> sz;
int par[Maxn*2],rank[Maxn*2];
int num[Maxn];
void init(int n)
{
	for(int i=1;i<=2*n;i++)
	{
		par[i] = i;
		rank[i] = 0;
	}
	memset(num,0,sizeof num);
}

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

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

int main()
{
	while(~scanf("%d%d%d",&N,&K,&L))
	{
		init(N);
		int a,b;
		for(int i=1;i<=K;i++)
		{
			scanf("%d%d",&a,&b);
			unite(a,b);
		}
		for(int i=1;i<=L;i++)
		{
			scanf("%d%d",&a,&b);
		//	if(same(a,b))
			{
				unite(a+N,b+N);
			}
		}
		for(int i=1;i<=N;i++)
		sz[mp(find(i),find(i+N))]++;
	/*	for(int i=N+1;i<=2*N;i++)
		{
			find(i);
			num[par[i]-N]++;
		}
		for(int i=N+1;i<=2*N;i++)
		{
			if(par[i]!=i)
			num[i-N] = num[par[i]-N];
		}*/
		for(int i=1;i<=N;i++)
		{
			printf("%d",sz[mp(find(i),find(i+N))]);
			if(i!=N)
			printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Compiler output:
a.cc: In function 'void init(int)':
a.cc:17:17: error: reference to 'rank' is ambiguous
   17 |                 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/bits/stl_tree.h:63,
                 from /usr/include/c++/14/map:62,
                 from a.cc:2:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:10:17: note:                 'int rank [400020]'
   10 | int par[Maxn*2],rank[Maxn*2];
      |                 ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:35:12: error: reference to 'rank' is ambiguous
   35 |         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:10:17: note:                 'int rank [400020]'
   10 | int par[Maxn*2],rank[Maxn*2];
      |                 ^~~~
a.cc:35:22: error: reference to 'rank' is ambiguous
   35 |         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:10:17: note:                 'int rank [400020]'
   10 | int par[Maxn*2],rank[Maxn*2];
      |                 ^~~~
a.cc:40:20: error: reference to 'rank' is ambiguous
   40 |                 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:10:17: note:                 'int rank [400020]'
   10 | int par[Maxn*2],rank[Maxn*2];
      |                 ^~~~
a.cc:40:31: error: reference to 'rank' is ambiguous
   40 |                 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:10:17: note:                 'int rank [400020]'
   10 | int par[Maxn*2],rank[Maxn*2];
      |                 ^~~~
a.cc:41:17: error: reference to 'rank' is ambiguous
   41 |                 rank[x]++;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:10:17: note:                 'int rank [400020]'
   10 | int par[Maxn*2],rank[Maxn*2];
      |                 ^~~~