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.319649171574772x):
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <vector>

#include <map>

using namespace std;

const int N = 200005;

int n,x,y,ans[N];

// road

int k, knm[N],kfa[N];



int kfind(int t){

	if(t == kfa[t]) return t;

	return kfa[t] = kfind(kfa[t]);

}

// raiway

int l, lnm[N],lfa[N];

int lfind(int t){

	if(t == lfa[t]) return t;

	return lfa[t] = lfind(lfa[t]);

}



map<pair<int, int>, int> mp;



int main(){

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

	// k

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

		kfa[i] = i;

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

		scanf("%d%d",&x,&y);

		int tx = kfind(x), ty = kfind(y);

		if(tx != ty)

			kfa[ty] = tx;

	}

	

	// l

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

		lfa[i] = i;	

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

		scanf("%d%d",&x,&y);

		int tx = lfind(x), ty = lfind(y);

		if(tx != ty)

			lfa[ty] = tx;

	}

	

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

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

//	cout<<endl;

	//cout<<kfa[3]<<" "<<lfa[3]<<endl;

	//cout<<kfa[5]<<" "<<lfa[5]<<endl;

	

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

		++ mp[make_pair(kfind(i), lfind(i))];

	}

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

		ans[i] = mp[make_pair(kfind(i), lfind(i))];

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

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

	printf("%d\n", ans[n]); 

}
// 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.3659030788241715x):
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <vector>

#include <map>

using namespace std;

const int N = 200005;

int n,x,y,ans[N];

// road

int k, knm[N],kfa[N];



int kfind(int t){

	if(t == kfa[t]) return t;

	return kfa[t] = kfind(kfa[t]);

}

// raiway

int l, lnm[N],lfa[N];

int lfind(int t){

	if(t == lfa[t]) return t;

	return lfa[t] = lfind(lfa[t]);

}



map<pair<int, int>, int> mp;



int main(){

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

	// k

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

		kfa[i] = i;

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

		scanf("%d%d",&x,&y);

		int tx = kfind(x), ty = kfind(y);

		if(tx != ty)

			kfa[ty] = tx;

	}

	

	// l

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

		lfa[i] = i;	

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

		scanf("%d%d",&x,&y);

		int tx = lfind(x), ty = lfind(y);

		if(tx != ty)

			lfa[ty] = tx;

	}

	

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

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

//	cout<<endl;

	//cout<<kfa[3]<<" "<<lfa[3]<<endl;

	//cout<<kfa[5]<<" "<<lfa[5]<<endl;

	

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

		++ mp[make_pair(kfind(i), lfind(i))];

	}

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

		ans[i] = mp[make_pair(kfind(i), lfind(i))];

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

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

	printf("%d\n", ans[n]); 

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const int N = 220000;



vector<int> con[N];



int root[N];

inline int find_root(int u) {

	if (u == root[u]) return root[u];

	return root[u] = find_root(root[u]);

}



int vis[N];

vector<int> cur;

void dfs(int u) {

	vis[u] = 1;

	cur.push_back(u);

	for (int v : con[u]) if (!vis[v]) dfs(v);

}



int cnt[N];

int ans[N];



int main() {

	

	ios::sync_with_stdio(0);

	cin.tie(0), cout.tie(0);

	

	int n, m, k; cin >> n >> m >> k;

	for (int i = 1; i <= n; i++) root[i] = i;

	while (m--) {

		int u, v; cin >> u >> v;

		int a = find_root(u), b = find_root(v);

		if (a == b) continue;

		root[a] = b;

	}

	while (k--) {

		int u, v; cin >> u >> v;

		con[u].push_back(v), con[v].push_back(u);

	}

	for (int i = 1; i <= n; i++) if (!vis[i]) {

		cur.clear();

		dfs(i);

		for (auto u : cur) cnt[find_root(u)] = 0;

		for (auto u : cur) cnt[find_root(u)]++;

		for (auto u : cur) ans[u] = cnt[find_root(u)];

	}

	for (int i = 1; i <= n; i++) cout << ans[i] << " \n"[i == n];

	

	return 0;

}


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

#include <cstdio>

#include <algorithm>

#include <vector>

#include <map>

using namespace std;

const int N = 200005;

int n,x,y,ans[N];

// road

int k, knm[N],kfa[N];



int kfind(int t){

	if(t == kfa[t]) return t;

	return kfa[t] = kfind(kfa[t]);

}

// raiway

int l, lnm[N],lfa[N];

int lfind(int t){

	if(t == lfa[t]) return t;

	return lfa[t] = lfind(lfa[t]);

}



map<pair<int, int>, int> mp;



int main(){

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

	// k

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

		kfa[i] = i;

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

		scanf("%d%d",&x,&y);

		int tx = kfind(x), ty = kfind(y);

		if(tx != ty)

			kfa[ty] = tx;

	}

	

	// l

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

		lfa[i] = i;	

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

		scanf("%d%d",&x,&y);

		int tx = lfind(x), ty = lfind(y);

		if(tx != ty)

			lfa[ty] = tx;

	}

	

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

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

//	cout<<endl;

	//cout<<kfa[3]<<" "<<lfa[3]<<endl;

	//cout<<kfa[5]<<" "<<lfa[5]<<endl;

	

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

		++ mp[make_pair(kfind(i), lfind(i))];

	}

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

		ans[i] = mp[make_pair(kfind(i), lfind(i))];

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

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

	printf("%d\n", ans[n]); 

}
// 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: 1.2631165975001453x):
#include<iostream>

#include<string.h>

#include<vector>

#include<algorithm>

#include<map>

using namespace std;

#define ll long long 

#define ull unsigned long long

#define pb push_back

const int maxn = 200005;

const ll mod = 1000000007;

int fa[maxn], fb[maxn];

void init() {

    for (int i = 0; i < maxn; i++) fa[i] = i, fb[i] = i;

}

int fi(int* k, int x) {

    return x == k[x] ? x : k[x] = fi(k, k[x]);

}

void Union(int* k, int x, int y) {

    int fx = fi(k, x), fy = fi(k, y);

    if (fx != fy) k[fy] = fx;

}

map<pair<int, int>, int>mp;

int main() {

    ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);

    int n, k, l, x, y;

    init();

    cin >> n >> k >> l;

    while (k--) {

        cin >> x >> y;

        Union(fa, x, y);

    }

    while (l--) {

        cin >> x >> y;

        Union(fb, x, y);

    }

    for (int i = 1; i <= n; i++)  mp[make_pair(fi(fa, i), fi(fb, i))]++;

    for (int i = 1; i <= n; i++) cout<<mp[make_pair(fi(fa, i), fi(fb, i))]<<" ";

    cout<< '\n';

    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: 2.4222071132672323x):
#include<iostream>

#include<string.h>

#include<vector>

#include<algorithm>

#include<map>

using namespace std;

#define ll long long 

#define ull unsigned long long

#define pb push_back

const int maxn = 200005;

const ll mod = 1000000007;

int fa[maxn], fb[maxn];

void init() {

    for (int i = 0; i < maxn; i++) fa[i] = i, fb[i] = i;

}

int fi(int* k, int x) {

    return x == k[x] ? x : k[x] = fi(k, k[x]);

}

void Union(int* k, int x, int y) {

    int fx = fi(k, x), fy = fi(k, y);

    if (fx != fy) k[fy] = fx;

}

map<pair<int, int>, int>mp;

int main() {

    ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);

    int n, k, l, x, y;

    init();

    cin >> n >> k >> l;

    while (k--) {

        cin >> x >> y;

        Union(fa, x, y);

    }

    while (l--) {

        cin >> x >> y;

        Union(fb, x, y);

    }

    for (int i = 1; i <= n; i++)  mp[make_pair(fi(fa, i), fi(fb, i))]++;

    for (int i = 1; i <= n; i++) cout<<mp[make_pair(fi(fa, i), fi(fb, i))]<<" ";

    cout<< '\n';

    return 0;



}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const int N = 220000;



vector<int> con[N];



int root[N];

inline int find_root(int u) {

	if (u == root[u]) return root[u];

	return root[u] = find_root(root[u]);

}



int vis[N];

vector<int> cur;

void dfs(int u) {

	vis[u] = 1;

	cur.push_back(u);

	for (int v : con[u]) if (!vis[v]) dfs(v);

}



int cnt[N];

int ans[N];



int main() {

	

	ios::sync_with_stdio(0);

	cin.tie(0), cout.tie(0);

	

	int n, m, k; cin >> n >> m >> k;

	for (int i = 1; i <= n; i++) root[i] = i;

	while (m--) {

		int u, v; cin >> u >> v;

		int a = find_root(u), b = find_root(v);

		if (a == b) continue;

		root[a] = b;

	}

	while (k--) {

		int u, v; cin >> u >> v;

		con[u].push_back(v), con[v].push_back(u);

	}

	for (int i = 1; i <= n; i++) if (!vis[i]) {

		cur.clear();

		dfs(i);

		for (auto u : cur) cnt[find_root(u)] = 0;

		for (auto u : cur) cnt[find_root(u)]++;

		for (auto u : cur) ans[u] = cnt[find_root(u)];

	}

	for (int i = 1; i <= n; i++) cout << ans[i] << " \n"[i == n];

	

	return 0;

}


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

#include<string.h>

#include<vector>

#include<algorithm>

#include<map>

using namespace std;

#define ll long long 

#define ull unsigned long long

#define pb push_back

const int maxn = 200005;

const ll mod = 1000000007;

int fa[maxn], fb[maxn];

void init() {

    for (int i = 0; i < maxn; i++) fa[i] = i, fb[i] = i;

}

int fi(int* k, int x) {

    return x == k[x] ? x : k[x] = fi(k, k[x]);

}

void Union(int* k, int x, int y) {

    int fx = fi(k, x), fy = fi(k, y);

    if (fx != fy) k[fy] = fx;

}

map<pair<int, int>, int>mp;

int main() {

    ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);

    int n, k, l, x, y;

    init();

    cin >> n >> k >> l;

    while (k--) {

        cin >> x >> y;

        Union(fa, x, y);

    }

    while (l--) {

        cin >> x >> y;

        Union(fb, x, y);

    }

    for (int i = 1; i <= n; i++)  mp[make_pair(fi(fa, i), fi(fb, i))]++;

    for (int i = 1; i <= n; i++) cout<<mp[make_pair(fi(fa, i), fi(fb, i))]<<" ";

    cout<< '\n';

    return 0;



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

#include <string.h>

#include <stdio.h>

#include <queue>

#include <vector>

#include <map>

#include <algorithm>

using namespace std;

const int Max=3e5+100;

int get_root(int *f, int root){

    return f[root]==root?root:f[root]=get_root(f, f[root]);

}

void merge(int *f, int x,int y){

    int i=get_root(f, x);

    int j=get_root(f, y);

    f[i]=j;

}

int f[Max], g[Max];

void init(int n){

    for(int a=0; a<=n; a++)f[a]=a, g[a]=a;

}

int vis[Max], num[Max];

vector<int> vec[Max];

map<int, int>ma;

int main(){

    int n, m, k, u, v;

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

    init(n);

    for(int a=0; a<m; a++){

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

        merge(f, u, v);

    }

    for(int a=0; a<k; a++){

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

        merge(g, u, v);

    }

    for(int a=1; a<=n; a++)vec[get_root(f, a)].push_back(a);

    for(int a=0; a<=n; a++){

        ma.clear();

       // memset(num, 0, sizeof(num));

        for(int b=0; b<vec[a].size(); b++){

            ma[get_root(g, vec[a][b])]++;

            //num[get_root(g, vec[a][b])]++;

        }

        for(int b=0; b<vec[a].size(); b++){

            vis[vec[a][b]]+=ma[get_root(g, vec[a][b])];

        }

    }

    for(int a=1; a<=n; a++)printf("%d%c", vis[a], a==n?'\n':' ');

    return  0;

}

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

using namespace std;

const int maxn = 2e5+7;

int f1[maxn],f2[maxn];

int n,k,l,x,y;

map<pair<int,int>,int >o;

int getf(int a[],int x)

{

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

  else

  {

      a[x] = getf(a,a[x]);

      return a[x];

  }

}

void amerge(int a[],int x,int y)

{

        int x1 = getf(a,x);

        int x2  = getf(a,y);

        if(x1==x2)

            return;

        else

            a[x1] =x2;

}

void init(int a[])

{

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

        a[i]  = i;

}

int main()

{

    while(cin>>n>>k>>l)

    {

        init(f1);

        init(f2);

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

        {

            scanf("%d%d",&x,&y);

            amerge(f1,x,y);

        }

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

        {

            scanf("%d%d",&x,&y);

            amerge(f2,x,y);

        }

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

        {

            ++o[{getf(f1,i),getf(f2,i)}];

        }

        int top = 1;

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

        {

                if(top)top = 0;

               else printf(" ");

            printf("%d",o[{getf(f1,i),getf(f2,i)}]);

        }

        printf("\n");

    }

    return 0;

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

#include <string.h>

#include <stdio.h>

#include <queue>

#include <vector>

#include <map>

#include <algorithm>

using namespace std;

const int Max=3e5+100;

int get_root(int *f, int root){

    return f[root]==root?root:f[root]=get_root(f, f[root]);

}

void merge(int *f, int x,int y){

    int i=get_root(f, x);

    int j=get_root(f, y);

    f[i]=j;

}

int f[Max], g[Max];

void init(int n){

    for(int a=0; a<=n; a++)f[a]=a, g[a]=a;

}

int vis[Max], num[Max];

vector<int> vec[Max];

map<int, int>ma;

int main(){

    int n, m, k, u, v;

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

    init(n);

    for(int a=0; a<m; a++){

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

        merge(f, u, v);

    }

    for(int a=0; a<k; a++){

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

        merge(g, u, v);

    }

    for(int a=1; a<=n; a++)vec[get_root(f, a)].push_back(a);

    for(int a=0; a<=n; a++){

        ma.clear();

       // memset(num, 0, sizeof(num));

        for(int b=0; b<vec[a].size(); b++){

            ma[get_root(g, vec[a][b])]++;

            //num[get_root(g, vec[a][b])]++;

        }

        for(int b=0; b<vec[a].size(); b++){

            vis[vec[a][b]]+=ma[get_root(g, vec[a][b])];

        }

    }

    for(int a=1; a<=n; a++)printf("%d%c", vis[a], a==n?'\n':' ');

    return  0;

}

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

#include<algorithm>

#include<cstring>

#include<vector>

#include<queue>

#include<map>

using namespace std;

#define LL long long

#define MAXN 200010

map<LL,int>G;

LL col[MAXN];

int vis[MAXN],n,a,b;

int Adj[MAXN],V[MAXN],nxt[MAXN],c;

void AddEdge(int u,int v)

{

	c++;V[c]=v,nxt[c]=Adj[u];

	Adj[u]=c;

}

void dfs1(int u)

{

	vis[u]=1;

	col[u]=col[0];

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

		if(!vis[V[i]])

			dfs1(V[i]);

}

void dfs2(int u)

{

	vis[u]=0;

	col[u]=(col[u]<<20)+col[0];

	G[col[u]]++;

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

		if(vis[V[i]])

			dfs2(V[i]);

}

int main()

{

	int u,v;

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

	for(int i=0;i<a;i++)

	{

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

		AddEdge(u,v);

		AddEdge(v,u);

	}

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

		if(!vis[i])

		{

			col[0]++;

			dfs1(i);

		}

	memset(Adj,0,sizeof Adj);

	col[0]=0,c=0;

	for(int i=0;i<b;i++)

	{

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

		AddEdge(u,v);

		AddEdge(v,u);

	}

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

		if(vis[i])

		{

			col[0]++;

			dfs2(i);

		}

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

		printf("%d ",G[col[i]]);

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

#include <string.h>

#include <stdio.h>

#include <queue>

#include <vector>

#include <map>

#include <algorithm>

using namespace std;

const int Max=3e5+100;

int get_root(int *f, int root){

    return f[root]==root?root:f[root]=get_root(f, f[root]);

}

void merge(int *f, int x,int y){

    int i=get_root(f, x);

    int j=get_root(f, y);

    f[i]=j;

}

int f[Max], g[Max];

void init(int n){

    for(int a=0; a<=n; a++)f[a]=a, g[a]=a;

}

int vis[Max], num[Max];

vector<int> vec[Max];

map<int, int>ma;

int main(){

    int n, m, k, u, v;

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

    init(n);

    for(int a=0; a<m; a++){

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

        merge(f, u, v);

    }

    for(int a=0; a<k; a++){

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

        merge(g, u, v);

    }

    for(int a=1; a<=n; a++)vec[get_root(f, a)].push_back(a);

    for(int a=0; a<=n; a++){

        ma.clear();

       // memset(num, 0, sizeof(num));

        for(int b=0; b<vec[a].size(); b++){

            ma[get_root(g, vec[a][b])]++;

            //num[get_root(g, vec[a][b])]++;

        }

        for(int b=0; b<vec[a].size(); b++){

            vis[vec[a][b]]+=ma[get_root(g, vec[a][b])];

        }

    }

    for(int a=1; a<=n; a++)printf("%d%c", vis[a], a==n?'\n':' ');

    return  0;

}

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

#include<map>

#include<iostream>

using namespace std;

const int MAXN = 2*int(1E5);

int fa1[MAXN + 5], fa2[MAXN + 5];

int Find1(int x) {

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

	else return fa1[x] = Find1(fa1[x]);

}

int Find2(int x) {

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

	else return fa2[x] = Find2(fa2[x]);

}

map<pair<int, int>, int> Map;

int main() {

	int N, K, L;

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

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

		fa1[i] = fa2[i] = i;

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

		int u, v;

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

		int fx = Find1(u), fy = Find1(v);

		fa1[fx] = fy;

	}

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

		int u, v;

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

		int fx = Find2(u), fy = Find2(v);

		fa2[fx] = fy;

	}

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

		Map[make_pair(Find1(i),Find2(i))]++;

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

		printf("%d ", Map[make_pair(Find1(i),Find2(i))]);

	printf("%d\n", Map[make_pair(Find1(N),Find2(N))]);

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

#include<algorithm>

#include<cstring>

#include<vector>

#include<queue>

#include<map>

using namespace std;

#define LL long long

#define MAXN 200010

map<LL,int>G;

LL col[MAXN];

int vis[MAXN],n,a,b;

int Adj[MAXN],V[MAXN],nxt[MAXN],c;

void AddEdge(int u,int v)

{

	c++;V[c]=v,nxt[c]=Adj[u];

	Adj[u]=c;

}

void dfs1(int u)

{

	vis[u]=1;

	col[u]=col[0];

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

		if(!vis[V[i]])

			dfs1(V[i]);

}

void dfs2(int u)

{

	vis[u]=0;

	col[u]=(col[u]<<20)+col[0];

	G[col[u]]++;

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

		if(vis[V[i]])

			dfs2(V[i]);

}

int main()

{

	int u,v;

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

	for(int i=0;i<a;i++)

	{

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

		AddEdge(u,v);

		AddEdge(v,u);

	}

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

		if(!vis[i])

		{

			col[0]++;

			dfs1(i);

		}

	memset(Adj,0,sizeof Adj);

	col[0]=0,c=0;

	for(int i=0;i<b;i++)

	{

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

		AddEdge(u,v);

		AddEdge(v,u);

	}

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

		if(vis[i])

		{

			col[0]++;

			dfs2(i);

		}

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

		printf("%d ",G[col[i]]);

}

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

#include<map>

#include<iostream>

using namespace std;

const int MAXN = 2*int(1E5);

int fa1[MAXN + 5], fa2[MAXN + 5];

int Find1(int x) {

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

	else return fa1[x] = Find1(fa1[x]);

}

int Find2(int x) {

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

	else return fa2[x] = Find2(fa2[x]);

}

map<pair<int, int>, int> Map;

int main() {

	int N, K, L;

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

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

		fa1[i] = fa2[i] = i;

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

		int u, v;

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

		int fx = Find1(u), fy = Find1(v);

		fa1[fx] = fy;

	}

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

		int u, v;

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

		int fx = Find2(u), fy = Find2(v);

		fa2[fx] = fy;

	}

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

		Map[make_pair(Find1(i),Find2(i))]++;

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

		printf("%d ", Map[make_pair(Find1(i),Find2(i))]);

	printf("%d\n", Map[make_pair(Find1(N),Find2(N))]);

}