stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<cmath>

#include<map>

#include<algorithm>



#define maxn 200005



using namespace std;



inline int getint()

{

	int num=0,flag=1;char c;

	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;

	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();

	return num*flag;

}



map<long long,int>sz;

int n,k,l;

int fir[maxn],nxt[maxn],to[maxn],cnt;

int f1[maxn];

int f2[maxn];



inline void newnode(int u,int v)

{to[++cnt]=v,nxt[cnt]=fir[u],fir[u]=cnt;}



void dfs1(int u)

{

	for(int i=fir[u];i;i=nxt[i])

		if(!f1[to[i]])

		{

			f1[to[i]]=f1[u];

			dfs1(to[i]);

		}

}



void dfs2(int u)

{

	for(int i=fir[u];i;i=nxt[i])

		if(!f2[to[i]])

		{

			f2[to[i]]=f2[u];

			dfs2(to[i]);

		}

}





int main()

{

	n=getint(),k=getint(),l=getint();

	for(int i=1;i<=k;i++)

	{

		int a=getint(),b=getint();

		newnode(a,b),newnode(b,a);

	}

	for(int i=1;i<=n;i++)

		if(!f1[i])f1[i]=i,dfs1(i);

	memset(fir,0,sizeof fir);memset(nxt,0,sizeof nxt);

	memset(to,0,sizeof to);cnt=0;

	for(int i=1;i<=l;i++)

	{

		int a=getint(),b=getint();

		newnode(a,b),newnode(b,a);

	}

	for(int i=1;i<=n;i++)

		if(!f2[i])f2[i]=i,dfs2(i);

	for(int i=1;i<=n;i++)

		sz[(long long)f1[i]*maxn+f2[i]]++;

	for(int i=1;i<=n;i++)

		if(i==n)printf("%d\n",sz[(long long)f1[i]*maxn+f2[i]]);

		else printf("%d ",sz[(long long)f1[i]*maxn+f2[i]]);

}

// Faster C++ solution for the same problem (measured speedup: 3.572818570834792x):
#include<cstdio>

#include<cstring>

#include<map>

#include<algorithm>

using namespace std;

#define N 200005

#define M 100005

struct node1{

	int to,nxt;

}e1[2*M];

int fir1[N],cnt1;

void adde1(int a,int b)

{

	e1[++cnt1].to=b;

	e1[cnt1].nxt=fir1[a];

	fir1[a]=cnt1;

	e1[++cnt1].to=a;

	e1[cnt1].nxt=fir1[b];

	fir1[b]=cnt1;

}

int vis1[N],tot1;

void dfs1(int u)

{

	int v,p;

	vis1[u]=tot1;

	for(p=fir1[u];p;p=e1[p].nxt){

		v=e1[p].to;

		if(!vis1[v])

			dfs1(v);

	}

}



struct node2{

	int to,nxt;

}e2[2*M];

int fir2[N],cnt2;

void adde2(int a,int b)

{

	e2[++cnt2].to=b;

	e2[cnt2].nxt=fir2[a];

	fir2[a]=cnt2;

	e2[++cnt2].to=a;

	e2[cnt2].nxt=fir2[b];

	fir2[b]=cnt2;

}

int vis2[N],tot2;

void dfs2(int u)

{

	int v,p;

	vis2[u]=tot2;

	for(p=fir2[u];p;p=e2[p].nxt){

		v=e2[p].to;

		if(!vis2[v])

			dfs2(v);

	}

}

map<long long,int >b;

int main()

{

	int n,m1,m2,u,v,i;

	scanf("%d%d%d",&n,&m1,&m2);

	for(i=1;i<=m1;i++){

		scanf("%d%d",&u,&v);

		adde1(u,v);

	}

	for(i=1;i<=n;i++)

		if(!vis1[i]){tot1++;dfs1(i);}

	

	for(i=1;i<=m2;i++){

		scanf("%d%d",&u,&v);

		adde2(u,v);

	}

	for(i=1;i<=n;i++)

		if(!vis2[i]){tot2++;dfs2(i);}

	

	for(i=1;i<=n;i++)

		b[1ll*vis1[i]*N+1ll*vis2[i]]++;

	for(i=1;i<=n;i++){

		printf("%d",b[1ll*vis1[i]*N+1ll*vis2[i]]);

		if(i!=n)printf(" ");

	}

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<cmath>

#include<map>

#include<algorithm>



#define maxn 200005



using namespace std;



inline int getint()

{

	int num=0,flag=1;char c;

	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;

	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();

	return num*flag;

}



map<long long,int>sz;

int n,k,l;

int fir[maxn],nxt[maxn],to[maxn],cnt;

int f1[maxn];

int f2[maxn];



inline void newnode(int u,int v)

{to[++cnt]=v,nxt[cnt]=fir[u],fir[u]=cnt;}



void dfs1(int u)

{

	for(int i=fir[u];i;i=nxt[i])

		if(!f1[to[i]])

		{

			f1[to[i]]=f1[u];

			dfs1(to[i]);

		}

}



void dfs2(int u)

{

	for(int i=fir[u];i;i=nxt[i])

		if(!f2[to[i]])

		{

			f2[to[i]]=f2[u];

			dfs2(to[i]);

		}

}





int main()

{

	n=getint(),k=getint(),l=getint();

	for(int i=1;i<=k;i++)

	{

		int a=getint(),b=getint();

		newnode(a,b),newnode(b,a);

	}

	for(int i=1;i<=n;i++)

		if(!f1[i])f1[i]=i,dfs1(i);

	memset(fir,0,sizeof fir);memset(nxt,0,sizeof nxt);

	memset(to,0,sizeof to);cnt=0;

	for(int i=1;i<=l;i++)

	{

		int a=getint(),b=getint();

		newnode(a,b),newnode(b,a);

	}

	for(int i=1;i<=n;i++)

		if(!f2[i])f2[i]=i,dfs2(i);

	for(int i=1;i<=n;i++)

		sz[(long long)f1[i]*maxn+f2[i]]++;

	for(int i=1;i<=n;i++)

		if(i==n)printf("%d\n",sz[(long long)f1[i]*maxn+f2[i]]);

		else printf("%d ",sz[(long long)f1[i]*maxn+f2[i]]);

}

// Faster C++ solution for the same problem (measured speedup: 3.2851771157589624x):
#include<string>

#include<iostream>

#include<map>

using namespace std;

int head[200001],num_edge,n,l,p,fa[200001];

struct Edge

{

	int next,to;

}edge[200001];

int v[200001],ans[200001];

void add(int from,int to)

{

	edge[++num_edge].next=head[from];

	edge[num_edge].to=to;

	head[from]=num_edge;

}

int find(int x)

{

    if(fa[x]==x) return x;

    else return fa[x]=find(fa[x]);

}

void get_together(int a,int b)

{

    fa[find(a)]=find(b);

}

void dfs1(int x,int tag,map<int,int>&num)

{

	if(v[x]==tag) return ;

	v[x]=tag;

	num[find(x)]++;

	for(int i=head[x];i;i=edge[i].next)

	  dfs1(edge[i].to,tag,num);

}

void dfs2(int x,int tag,map<int,int>&num)

{

	if(v[x]==tag) return ;

	v[x]=tag;

	ans[x]+=num[find(x)];

	for(int i=head[x];i;i=edge[i].next)

	  dfs2(edge[i].to,tag,num);

}

int main(){

	cin>>n>>p>>l;

	for(int i=1;i<=n;i++)

	  fa[i]=i;

	for(int i=1;i<=p;i++)

	{

		int a,b;

		cin>>a>>b;

		get_together(a,b);

	}

	for(int i=1;i<=l;i++)

	{

		int a,b;

		cin>>a>>b;

		add(a,b);

		add(b,a);

	}

	for(int i=1;i<=n;i++)

	  if(!v[i])

	  {

	  	map<int,int> num;

	  	dfs1(i,i,num);

	  	dfs2(i,-i,num);

	  }

	for(int i=1;i<=n;i++)

	  cout<<ans[i]<<' ';

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<map>

#include<vector>

#include<algorithm>

#define MAXN 200006

using namespace std;

int n,K,L,fa[3][MAXN],u,v,sum[MAXN];

vector<int> road[MAXN];

map<int,int> ma;

int root(int x,int op)

{

	if(fa[op][x]==x) return x;

	fa[op][x]=root(fa[op][x],op);

	return fa[op][x];

}

int main()

{

	scanf("%d%d%d",&n,&K,&L);

	for(int i=1;i<=n;i++)

	{

		fa[0][i]=i;

		fa[1][i]=i;

	}

	for(int i=1;i<=K;i++)

	{

		scanf("%d%d",&u,&v);

		fa[0][root(u,0)]=root(v,0);

	}

	for(int i=1;i<=L;i++)

	{

		scanf("%d%d",&u,&v);

		fa[1][root(u,1)]=root(v,1);

	}

	for(int i=1;i<=n;i++)

		road[root(i,0)].push_back(i);

	for(int i=1;i<=n;i++)

	{

		ma.clear();

		for(int j=0;j<(int)road[i].size();j++)

			ma[root(road[i][j],1)]++;

		for(int j=0;j<(int)road[i].size();j++)

			sum[road[i][j]]+=ma[root(road[i][j],1)];

	}

	for(int i=1;i<=n;i++)

		printf("%d ",sum[i]);

}

// Faster C++ solution for the same problem (measured speedup: 6.299797971052449x):
#include<string>

#include<iostream>

#include<map>

using namespace std;

int head[200001],num_edge,n,l,p,fa[200001];

struct Edge

{

	int next,to;

}edge[200001];

int v[200001],ans[200001];

void add(int from,int to)

{

	edge[++num_edge].next=head[from];

	edge[num_edge].to=to;

	head[from]=num_edge;

}

int find(int x)

{

    if(fa[x]==x) return x;

    else return fa[x]=find(fa[x]);

}

void get_together(int a,int b)

{

    fa[find(a)]=find(b);

}

void dfs1(int x,int tag,map<int,int>&num)

{

	if(v[x]==tag) return ;

	v[x]=tag;

	num[find(x)]++;

	for(int i=head[x];i;i=edge[i].next)

	  dfs1(edge[i].to,tag,num);

}

void dfs2(int x,int tag,map<int,int>&num)

{

	if(v[x]==tag) return ;

	v[x]=tag;

	ans[x]+=num[find(x)];

	for(int i=head[x];i;i=edge[i].next)

	  dfs2(edge[i].to,tag,num);

}

int main(){

	cin>>n>>p>>l;

	for(int i=1;i<=n;i++)

	  fa[i]=i;

	for(int i=1;i<=p;i++)

	{

		int a,b;

		cin>>a>>b;

		get_together(a,b);

	}

	for(int i=1;i<=l;i++)

	{

		int a,b;

		cin>>a>>b;

		add(a,b);

		add(b,a);

	}

	for(int i=1;i<=n;i++)

	  if(!v[i])

	  {

	  	map<int,int> num;

	  	dfs1(i,i,num);

	  	dfs2(i,-i,num);

	  }

	for(int i=1;i<=n;i++)

	  cout<<ans[i]<<' ';

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<cmath>

#include<map>

#include<algorithm>



#define maxn 200005



using namespace std;



inline int getint()

{

	int num=0,flag=1;char c;

	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;

	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();

	return num*flag;

}



map<long long,int>sz;

int n,k,l;

int fir[maxn],nxt[maxn],to[maxn],cnt;

int f1[maxn];

int f2[maxn];



inline void newnode(int u,int v)

{to[++cnt]=v,nxt[cnt]=fir[u],fir[u]=cnt;}



void dfs1(int u)

{

	for(int i=fir[u];i;i=nxt[i])

		if(!f1[to[i]])

		{

			f1[to[i]]=f1[u];

			dfs1(to[i]);

		}

}



void dfs2(int u)

{

	for(int i=fir[u];i;i=nxt[i])

		if(!f2[to[i]])

		{

			f2[to[i]]=f2[u];

			dfs2(to[i]);

		}

}





int main()

{

	n=getint(),k=getint(),l=getint();

	for(int i=1;i<=k;i++)

	{

		int a=getint(),b=getint();

		newnode(a,b),newnode(b,a);

	}

	for(int i=1;i<=n;i++)

		if(!f1[i])f1[i]=i,dfs1(i);

	memset(fir,0,sizeof fir);memset(nxt,0,sizeof nxt);

	memset(to,0,sizeof to);cnt=0;

	for(int i=1;i<=l;i++)

	{

		int a=getint(),b=getint();

		newnode(a,b),newnode(b,a);

	}

	for(int i=1;i<=n;i++)

		if(!f2[i])f2[i]=i,dfs2(i);

	for(int i=1;i<=n;i++)

		sz[(long long)f1[i]*maxn+f2[i]]++;

	for(int i=1;i<=n;i++)

		if(i==n)printf("%d\n",sz[(long long)f1[i]*maxn+f2[i]]);

		else printf("%d ",sz[(long long)f1[i]*maxn+f2[i]]);

}

// Faster C++ solution for the same problem (measured speedup: 3.308025839071475x):
#include<iostream>

#include<map>

using namespace std;

struct rode{int x,y;}a[100001];

struct subway{int x,y;}b[100001];

int rtree[200100],stree[200100];

map< pair<int,int>,int>  num;

int findrroot(int root)

{

    int start,t;

    start=root;

    while(root!=rtree[root])

        root=rtree[root];

    while(start!=root)

    {

        t=rtree[start];

        rtree[start]=root;

        start=t;

    }

    return root;

}

int findsroot(int root)

{

    int start,t;

    start=root;

    while(root!=stree[root])

        root=stree[root];

    while(start!=root)

    {

        t=stree[start];

        stree[start]=root;

        start=t;

    }

    return root;

}

int main()

{

    int N,K,L;

    int root1,root2;

    cin>>N>>K>>L;

    for(int i=1;i<=K;i++)

        cin>>a[i].x>>a[i].y;

    for(int i=1;i<=L;i++)

        cin>>b[i].x>>b[i].y;

    for(int i=1;i<=N;i++)

    {

        rtree[i]=i;

        stree[i]=i;

    }

    for(int i=1;i<=K;i++)

    {

        root1=findrroot(a[i].x);

        root2=findrroot(a[i].y);

        if(root1!=root2)

            rtree[root2]=root1;

        //for(int i=1;i<=N;i++)

//cout<<stree[i]<<" ";

        //cout<<endl;

    }

    for(int i=1;i<=L;i++)

    {

        root1=findsroot(b[i].x);

        root2=findsroot(b[i].y);

        if(root1!=root2)

            stree[root2]=root1;

    }

    for(int i=1;i<=N;i++)

    {

        findrroot(i);

        findsroot(i);

    }

    for(int i=1;i<=N;i++)

    {

        num[make_pair(rtree[i],stree[i])]++;

    }

    for(int i=1;i<=N;i++)

        cout<<num[make_pair(rtree[i],stree[i])]<<" ";

    return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<map>

#include<vector>

#include<algorithm>

#define MAXN 200006

using namespace std;

int n,K,L,fa[3][MAXN],u,v,sum[MAXN];

vector<int> road[MAXN];

map<int,int> ma;

int root(int x,int op)

{

	if(fa[op][x]==x) return x;

	fa[op][x]=root(fa[op][x],op);

	return fa[op][x];

}

int main()

{

	scanf("%d%d%d",&n,&K,&L);

	for(int i=1;i<=n;i++)

	{

		fa[0][i]=i;

		fa[1][i]=i;

	}

	for(int i=1;i<=K;i++)

	{

		scanf("%d%d",&u,&v);

		fa[0][root(u,0)]=root(v,0);

	}

	for(int i=1;i<=L;i++)

	{

		scanf("%d%d",&u,&v);

		fa[1][root(u,1)]=root(v,1);

	}

	for(int i=1;i<=n;i++)

		road[root(i,0)].push_back(i);

	for(int i=1;i<=n;i++)

	{

		ma.clear();

		for(int j=0;j<(int)road[i].size();j++)

			ma[root(road[i][j],1)]++;

		for(int j=0;j<(int)road[i].size();j++)

			sum[road[i][j]]+=ma[root(road[i][j],1)];

	}

	for(int i=1;i<=n;i++)

		printf("%d ",sum[i]);

}

// Faster C++ solution for the same problem (measured speedup: 6.343613672822323x):
#include<iostream>

#include<map>

using namespace std;

struct rode{int x,y;}a[100001];

struct subway{int x,y;}b[100001];

int rtree[200100],stree[200100];

map< pair<int,int>,int>  num;

int findrroot(int root)

{

    int start,t;

    start=root;

    while(root!=rtree[root])

        root=rtree[root];

    while(start!=root)

    {

        t=rtree[start];

        rtree[start]=root;

        start=t;

    }

    return root;

}

int findsroot(int root)

{

    int start,t;

    start=root;

    while(root!=stree[root])

        root=stree[root];

    while(start!=root)

    {

        t=stree[start];

        stree[start]=root;

        start=t;

    }

    return root;

}

int main()

{

    int N,K,L;

    int root1,root2;

    cin>>N>>K>>L;

    for(int i=1;i<=K;i++)

        cin>>a[i].x>>a[i].y;

    for(int i=1;i<=L;i++)

        cin>>b[i].x>>b[i].y;

    for(int i=1;i<=N;i++)

    {

        rtree[i]=i;

        stree[i]=i;

    }

    for(int i=1;i<=K;i++)

    {

        root1=findrroot(a[i].x);

        root2=findrroot(a[i].y);

        if(root1!=root2)

            rtree[root2]=root1;

        //for(int i=1;i<=N;i++)

//cout<<stree[i]<<" ";

        //cout<<endl;

    }

    for(int i=1;i<=L;i++)

    {

        root1=findsroot(b[i].x);

        root2=findsroot(b[i].y);

        if(root1!=root2)

            stree[root2]=root1;

    }

    for(int i=1;i<=N;i++)

    {

        findrroot(i);

        findsroot(i);

    }

    for(int i=1;i<=N;i++)

    {

        num[make_pair(rtree[i],stree[i])]++;

    }

    for(int i=1;i<=N;i++)

        cout<<num[make_pair(rtree[i],stree[i])]<<" ";

    return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<cmath>

#include<map>

#include<algorithm>



#define maxn 200005



using namespace std;



inline int getint()

{

	int num=0,flag=1;char c;

	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;

	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();

	return num*flag;

}



map<long long,int>sz;

int n,k,l;

int fir[maxn],nxt[maxn],to[maxn],cnt;

int f1[maxn];

int f2[maxn];



inline void newnode(int u,int v)

{to[++cnt]=v,nxt[cnt]=fir[u],fir[u]=cnt;}



void dfs1(int u)

{

	for(int i=fir[u];i;i=nxt[i])

		if(!f1[to[i]])

		{

			f1[to[i]]=f1[u];

			dfs1(to[i]);

		}

}



void dfs2(int u)

{

	for(int i=fir[u];i;i=nxt[i])

		if(!f2[to[i]])

		{

			f2[to[i]]=f2[u];

			dfs2(to[i]);

		}

}





int main()

{

	n=getint(),k=getint(),l=getint();

	for(int i=1;i<=k;i++)

	{

		int a=getint(),b=getint();

		newnode(a,b),newnode(b,a);

	}

	for(int i=1;i<=n;i++)

		if(!f1[i])f1[i]=i,dfs1(i);

	memset(fir,0,sizeof fir);memset(nxt,0,sizeof nxt);

	memset(to,0,sizeof to);cnt=0;

	for(int i=1;i<=l;i++)

	{

		int a=getint(),b=getint();

		newnode(a,b),newnode(b,a);

	}

	for(int i=1;i<=n;i++)

		if(!f2[i])f2[i]=i,dfs2(i);

	for(int i=1;i<=n;i++)

		sz[(long long)f1[i]*maxn+f2[i]]++;

	for(int i=1;i<=n;i++)

		if(i==n)printf("%d\n",sz[(long long)f1[i]*maxn+f2[i]]);

		else printf("%d ",sz[(long long)f1[i]*maxn+f2[i]]);

}

// Faster C++ solution for the same problem (measured speedup: 3.319530082362654x):
#include<bits/stdc++.h>

using namespace std;

int par1[200001],par2[200001];

vector<pair<int,int>> idx;

map<pair<int,int>,int> cnt;

int rep1(int n)

{

    if(par1[n]==n)

        return n;

    return par1[n]=rep1(par1[n]);

}

int rep2(int n)

{

    if(par2[n]==n)

        return n;

    return par2[n]=rep2(par2[n]);

}

int main()

{

    int i,j;

    int n,k,l;

    int a,b,res=0;

    scanf("%d %d %d",&n,&k,&l);

    for(i=1;i<=n;i++){

        par1[i]=i;

        par2[i]=i;

    }

    for(i=0;i<k;i++){

        scanf("%d %d",&a,&b);

        swap(a,b);

        int r1=rep1(a);

        int r2=rep1(b);

        par1[r1]=r2;

    }

    for(i=0;i<l;i++){

        scanf("%d %d",&a,&b);

        int r1=rep2(a);

        int r2=rep2(b);

        par2[r1]=r2;

    }

    for(i=1;i<=n;i++){

        idx.push_back(make_pair(rep1(i),rep2(i)));

    }



    for(i=0;i<idx.size();i++){

        cnt[idx[i]]++;

        //printf("%d %d\n",idx[i].first,idx[i].second);

    }

    for(i=0;i<idx.size();i++)

        printf("%d ",cnt[idx[i]]);

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<map>

#include<vector>

#include<algorithm>

#define MAXN 200006

using namespace std;

int n,K,L,fa[3][MAXN],u,v,sum[MAXN];

vector<int> road[MAXN];

map<int,int> ma;

int root(int x,int op)

{

	if(fa[op][x]==x) return x;

	fa[op][x]=root(fa[op][x],op);

	return fa[op][x];

}

int main()

{

	scanf("%d%d%d",&n,&K,&L);

	for(int i=1;i<=n;i++)

	{

		fa[0][i]=i;

		fa[1][i]=i;

	}

	for(int i=1;i<=K;i++)

	{

		scanf("%d%d",&u,&v);

		fa[0][root(u,0)]=root(v,0);

	}

	for(int i=1;i<=L;i++)

	{

		scanf("%d%d",&u,&v);

		fa[1][root(u,1)]=root(v,1);

	}

	for(int i=1;i<=n;i++)

		road[root(i,0)].push_back(i);

	for(int i=1;i<=n;i++)

	{

		ma.clear();

		for(int j=0;j<(int)road[i].size();j++)

			ma[root(road[i][j],1)]++;

		for(int j=0;j<(int)road[i].size();j++)

			sum[road[i][j]]+=ma[root(road[i][j],1)];

	}

	for(int i=1;i<=n;i++)

		printf("%d ",sum[i]);

}

// Faster C++ solution for the same problem (measured speedup: 6.365674708191345x):
#include<bits/stdc++.h>

using namespace std;

int par1[200001],par2[200001];

vector<pair<int,int>> idx;

map<pair<int,int>,int> cnt;

int rep1(int n)

{

    if(par1[n]==n)

        return n;

    return par1[n]=rep1(par1[n]);

}

int rep2(int n)

{

    if(par2[n]==n)

        return n;

    return par2[n]=rep2(par2[n]);

}

int main()

{

    int i,j;

    int n,k,l;

    int a,b,res=0;

    scanf("%d %d %d",&n,&k,&l);

    for(i=1;i<=n;i++){

        par1[i]=i;

        par2[i]=i;

    }

    for(i=0;i<k;i++){

        scanf("%d %d",&a,&b);

        swap(a,b);

        int r1=rep1(a);

        int r2=rep1(b);

        par1[r1]=r2;

    }

    for(i=0;i<l;i++){

        scanf("%d %d",&a,&b);

        int r1=rep2(a);

        int r2=rep2(b);

        par2[r1]=r2;

    }

    for(i=1;i<=n;i++){

        idx.push_back(make_pair(rep1(i),rep2(i)));

    }



    for(i=0;i<idx.size();i++){

        cnt[idx[i]]++;

        //printf("%d %d\n",idx[i].first,idx[i].second);

    }

    for(i=0;i<idx.size();i++)

        printf("%d ",cnt[idx[i]]);

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<cmath>

#include<map>

#include<algorithm>



#define maxn 200005



using namespace std;



inline int getint()

{

	int num=0,flag=1;char c;

	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;

	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();

	return num*flag;

}



map<long long,int>sz;

int n,k,l;

int fir[maxn],nxt[maxn],to[maxn],cnt;

int f1[maxn];

int f2[maxn];



inline void newnode(int u,int v)

{to[++cnt]=v,nxt[cnt]=fir[u],fir[u]=cnt;}



void dfs1(int u)

{

	for(int i=fir[u];i;i=nxt[i])

		if(!f1[to[i]])

		{

			f1[to[i]]=f1[u];

			dfs1(to[i]);

		}

}



void dfs2(int u)

{

	for(int i=fir[u];i;i=nxt[i])

		if(!f2[to[i]])

		{

			f2[to[i]]=f2[u];

			dfs2(to[i]);

		}

}





int main()

{

	n=getint(),k=getint(),l=getint();

	for(int i=1;i<=k;i++)

	{

		int a=getint(),b=getint();

		newnode(a,b),newnode(b,a);

	}

	for(int i=1;i<=n;i++)

		if(!f1[i])f1[i]=i,dfs1(i);

	memset(fir,0,sizeof fir);memset(nxt,0,sizeof nxt);

	memset(to,0,sizeof to);cnt=0;

	for(int i=1;i<=l;i++)

	{

		int a=getint(),b=getint();

		newnode(a,b),newnode(b,a);

	}

	for(int i=1;i<=n;i++)

		if(!f2[i])f2[i]=i,dfs2(i);

	for(int i=1;i<=n;i++)

		sz[(long long)f1[i]*maxn+f2[i]]++;

	for(int i=1;i<=n;i++)

		if(i==n)printf("%d\n",sz[(long long)f1[i]*maxn+f2[i]]);

		else printf("%d ",sz[(long long)f1[i]*maxn+f2[i]]);

}

// Faster C++ solution for the same problem (measured speedup: 3.3206328288410907x):
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

struct dsu{

    int p[200002], sz[200002];

    void init(int n){

        for(int i=1;i<=n;i++) p[i] = i, sz[i] = 1;

    }

    int root(int a){

        return p[a] == a?a:(p[a]=root(p[a]));

    }

    void merge(int a, int b){

        a = root(a), b = root(b);

        if(a != b){

            sz[b] += sz[a];

            p[a] = b;

        }

    }

}d1, d2;

map<pii, int> dp;



int main(){

    int n, k, l;

    scanf("%d%d%d", &n, &k, &l);

    d1.init(n), d2.init(n);

    for(int i=1;i<=k;i++){

        int a, b;

        scanf("%d%d", &a, &b);

        d1.merge(a, b);

    }

    for(int i=1;i<=l;i++){

        int a, b;

        scanf("%d%d", &a, &b);

        d2.merge(a, b);

    }

    for(int i=1;i<=n;i++) dp[make_pair(d1.root(i), d2.root(i))]++;

    for(int i=1;i<=n;i++) printf("%d ", dp[make_pair(d1.root(i), d2.root(i))]);

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<map>

#include<vector>

#include<algorithm>

#define MAXN 200006

using namespace std;

int n,K,L,fa[3][MAXN],u,v,sum[MAXN];

vector<int> road[MAXN];

map<int,int> ma;

int root(int x,int op)

{

	if(fa[op][x]==x) return x;

	fa[op][x]=root(fa[op][x],op);

	return fa[op][x];

}

int main()

{

	scanf("%d%d%d",&n,&K,&L);

	for(int i=1;i<=n;i++)

	{

		fa[0][i]=i;

		fa[1][i]=i;

	}

	for(int i=1;i<=K;i++)

	{

		scanf("%d%d",&u,&v);

		fa[0][root(u,0)]=root(v,0);

	}

	for(int i=1;i<=L;i++)

	{

		scanf("%d%d",&u,&v);

		fa[1][root(u,1)]=root(v,1);

	}

	for(int i=1;i<=n;i++)

		road[root(i,0)].push_back(i);

	for(int i=1;i<=n;i++)

	{

		ma.clear();

		for(int j=0;j<(int)road[i].size();j++)

			ma[root(road[i][j],1)]++;

		for(int j=0;j<(int)road[i].size();j++)

			sum[road[i][j]]+=ma[root(road[i][j],1)];

	}

	for(int i=1;i<=n;i++)

		printf("%d ",sum[i]);

}

// Faster C++ solution for the same problem (measured speedup: 6.3677893826160865x):
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

struct dsu{

    int p[200002], sz[200002];

    void init(int n){

        for(int i=1;i<=n;i++) p[i] = i, sz[i] = 1;

    }

    int root(int a){

        return p[a] == a?a:(p[a]=root(p[a]));

    }

    void merge(int a, int b){

        a = root(a), b = root(b);

        if(a != b){

            sz[b] += sz[a];

            p[a] = b;

        }

    }

}d1, d2;

map<pii, int> dp;



int main(){

    int n, k, l;

    scanf("%d%d%d", &n, &k, &l);

    d1.init(n), d2.init(n);

    for(int i=1;i<=k;i++){

        int a, b;

        scanf("%d%d", &a, &b);

        d1.merge(a, b);

    }

    for(int i=1;i<=l;i++){

        int a, b;

        scanf("%d%d", &a, &b);

        d2.merge(a, b);

    }

    for(int i=1;i<=n;i++) dp[make_pair(d1.root(i), d2.root(i))]++;

    for(int i=1;i<=n;i++) printf("%d ", dp[make_pair(d1.root(i), d2.root(i))]);

}