Language: C++

#include<cstdio>
#include<set>
using namespace std;
int fa[2][200010],rank[2][200010];
int findroot(bool op,int x)
{
	return x==fa[op][x] ? x : fa[op][x]=findroot(op,fa[op][x]);
}
void Union(bool op,int U,int V)
{
	if(rank[op][U]<rank[op][V])
	  fa[op][U]=V;
	else 
	 {
	 	fa[op][V]=U;
	 	if(rank[op][U]==rank[op][V])
	 	  ++rank[op][U];
	 }
}
int n,m,K;
bool vis[200010];
int anss[200010];
set<int>S[2][200010];
typedef set<int>::iterator ITER;
int path[200010],e;
int main()
{
	int x,y;
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;++i)
	  fa[0][i]=fa[1][i]=i;
	for(int i=1;i<=m;++i)
	  {
	  	scanf("%d%d",&x,&y);
	  	int f1=findroot(0,x),f2=findroot(0,y);
	  	if(f1!=f2)
	  	  Union(0,f1,f2);
	  }
	for(int i=1;i<=K;++i)
	  {
	  	scanf("%d%d",&x,&y);
	  	int f1=findroot(1,x),f2=findroot(1,y);
	  	if(f1!=f2)
	  	  Union(1,f1,f2);
	  }
	for(int i=0;i<=1;++i)
	  for(int j=1;j<=n;++j)
	    S[i][findroot(i,j)].insert(j);
	for(int i=1;i<=n;++i) if(!vis[i])
	  {
	  	e=0;
	  	int rt[2];
	  	bool o=0;
	  	rt[0]=findroot(0,i);
	  	rt[1]=findroot(1,i);
	  	if(S[0][rt[0]].size()>S[1][rt[1]].size())
	  	  o=1;
	  	set<int> tS=S[o][rt[o]];
	  	for(ITER it=tS.begin();it!=tS.end();++it)
	  	  if(S[o^1][rt[o^1]].find(*it)!=S[o^1][rt[o^1]].end())
	  	    {
	  	      S[o][rt[o]].erase(*it);
	  	      S[o^1][rt[o^1]].erase(*it);
	  	      path[++e]=(*it);
	  	      vis[*it]=1;
	  	    }
	  	for(int j=1;j<=e;++j)
	  	  anss[path[j]]=e;
	  }
	for(int i=1;i<n;++i)
	  printf("%d ",anss[i]);
	printf("%d\n",anss[n]);
	return 0;
}

Compiler output:
a.cc: In function 'void Union(bool, int, int)':
a.cc:11:12: error: reference to 'rank' is ambiguous
   11 |         if(rank[op][U]<rank[op][V])
      |            ^~~~
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/set: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:4:19: note:                 'int rank [2][200010]'
    4 | int fa[2][200010],rank[2][200010];
      |                   ^~~~
a.cc:11:24: error: reference to 'rank' is ambiguous
   11 |         if(rank[op][U]<rank[op][V])
      |                        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:4:19: note:                 'int rank [2][200010]'
    4 | int fa[2][200010],rank[2][200010];
      |                   ^~~~
a.cc:16:20: error: reference to 'rank' is ambiguous
   16 |                 if(rank[op][U]==rank[op][V])
      |                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:4:19: note:                 'int rank [2][200010]'
    4 | int fa[2][200010],rank[2][200010];
      |                   ^~~~
a.cc:16:33: error: reference to 'rank' is ambiguous
   16 |                 if(rank[op][U]==rank[op][V])
      |                                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:4:19: note:                 'int rank [2][200010]'
    4 | int fa[2][200010],rank[2][200010];
      |                   ^~~~
a.cc:17:21: error: reference to 'rank' is ambiguous
   17 |                   ++rank[op][U];
      |                     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:4:19: note:                 'int rank [2][200010]'
    4 | int fa[2][200010],rank[2][200010];
      |                   ^~~~