stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const int maxn = 200010;



int fa1[maxn], fa2[maxn], r1[maxn], r2[maxn];



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



void kexin_init() {

	for (int i=1; i<=maxn; ++i) {fa1[i] = i; fa2[i] = i;}

	memset(r1, 0, sizeof r1);

	memset(r2, 0, sizeof r2);

}



int kexin_find_road(int x) {

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

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

}

void kexin_Union_road(int x, int y) {

	x = kexin_find_road(x);

	y = kexin_find_road(y);

	if (x == y) return ;

	if (r1[x] < r1[y]) swap(x, y);

	fa1[y] = x;

	if (r1[x] == r1[y]) r1[x]++;

}



int kexin_find_railway(int x) {

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

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

}

void kexin_Union_railway(int x, int y) {

	x = kexin_find_railway(x);

	y = kexin_find_railway(y);

	if (x == y) return ;

	if (r2[x] < r2[y]) swap(x, y);

	fa2[y] = x;

	if (r2[x] == r2[y]) r2[x]++;

}

int main() {

	int n, k, l;

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

	

	kexin_init();

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

		int x, y;

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

		kexin_Union_road(x, y);

	}

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

		int x, y;

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

		kexin_Union_railway(x, y);

	}

	

	mp.clear();



	for (int i=1; i<=n; ++i) mp[make_pair(kexin_find_road(i), kexin_find_railway(i))]++;

	for (int i=1; i<n; ++i) printf("%d ", mp[make_pair(kexin_find_road(i), kexin_find_railway(i))]);

	printf("%d\n", mp[make_pair(kexin_find_road(n), kexin_find_railway(n))]);



	return 0;

}

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

using namespace std;

map<pair<int,int>,int>v;

const int MAX = 2e5 +5;

int rail[MAX],road[MAX];



int road_f(int x) {

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

  else return road[x] = road_f(road[x]);

}

int rail_f(int x) {

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

  else return rail[x] = rail_f(rail[x]);

}

int main() {

  int n,k,l,x,y;

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

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

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

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

    x = road_f(x),y = road_f(y);

    road[x] = y;

  }

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

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

    x = rail_f(x),y = rail_f(y);

    rail[x] = y;

  }

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

    road[i] = road_f(i);

    rail[i] = rail_f(i);

    v[make_pair(road[i],rail[i])]++;

  }

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

    printf("%d ",v[make_pair(road[i],rail[i])]);

  }

  printf("%d\n",v[make_pair(road[n],rail[n])]);

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

#include <map>

#include <vector>

using namespace std;



const int N = 2e5 + 5;

int pa1[N], pa2[N];

int find(int* p, int v) { return v == p[v] ? v : p[v] = find(p, p[v]); }

void unite(int* p, int a, int b) { p[find(p, b)] = find(p, a); }



typedef long long LL;

int n, k, l;

// vector<int> e1[N], e2[N];



map<LL, int> mp;



int main() {

#ifdef D

    freopen("a.in", "r", stdin);

#endif

    for (int i = 0; i < N; i++) {

        pa1[i] = pa2[i] = i;

    }

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

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

        int a, b;

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

        unite(pa1, a, b);

        // e1[a].push_back(b);

        // e1[b].push_back(a);

    }

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

        int a, b;

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

        unite(pa2, a, b);

        // e2[a].push_back(b);

        // e2[b].push_back(a);

    }



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

        mp[find(pa1, i) * (LL)(n + 1) + find(pa2, i)] += 1;

    }



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

        printf("%d ", mp[find(pa1, i) * (LL)(n + 1) + find(pa2, i)]);

    }

    puts("");



    return 0;

}


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

#include<string.h>

#include<set>

#include<stdlib.h>

#include<algorithm>

using namespace std;

int n,m1,m2;

int a1[400005],a2[400005];

int f1(int i){

	if(i==a1[i])return i;

	return a1[i]=f1(a1[i]);

}

int f2(int i){

	if(i==a2[i])return i;

	return a2[i]=f2(a2[i]);

}



long long line[1400005],g[400005],h[4000005],num;

int find(long long k){

	int i=1,mid,j=num;

	while(j-i>1){

		mid=(i+j)/2;

		if(k>line[mid])

		     i=mid;

		else j=mid;

		

	}

	if(line[i]==k)return h[i];

	return h[j];

	

}

int main(){

	

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

	for(int q=1;q<=n;q++)a1[q]=a2[q]=q;

	for(int q=1;q<=m1;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a1[f1(i)]=f1(j);

		

	}

	for(int q=1;q<=m2;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a2[f2(i)]=f2(j);

		

	}

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

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		g[q]=ppp;

		

	}

	sort(g+1,g+1+n);

	

	for(int q=1;q<=n;){

		

		line[++num]=g[q];

		int z=1;

		q++;

		while(g[q]==g[q-1]){

			q++;z++;

		}

		h[num]=z;

		if(q>n)break;

	}

	

	

	for(int q=1;q<=1;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf("%d",ans);

		

	}

	for(int q=2;q<=n;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf(" %d",ans);

		

	}

	printf("\n");

	

	return 0;

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

using namespace std;

#define LL long long

const int maxn = 2e5+10;

int n, k, l;

map<LL, int> num;

int fa[3][maxn];

LL Find (int x, int mod) {

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

    else return fa[mod][x] = Find (fa[mod][x], mod);

}

void Comb (int x, int y, int mod) {

    fa[mod][Find(x, mod)] = Find (y, mod);

}

LL id (int x) {

    return Find(x,0) * 1e6 + Find (x, 1);

}

int main (void) {

    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=  0; i < k; i++) {

        int a, b;

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

        Comb (a, b, 0);

    }

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

        int a, b;

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

        Comb (a, b, 1);

    };

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

        num[id(i)]++;

    }

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

        printf ("%d", num[id(i)]);

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

        else printf ("\n");

    }

    return 0;

}


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

#include<string.h>

#include<set>

#include<stdlib.h>

#include<algorithm>

using namespace std;

int n,m1,m2;

int a1[400005],a2[400005];

int f1(int i){

	if(i==a1[i])return i;

	return a1[i]=f1(a1[i]);

}

int f2(int i){

	if(i==a2[i])return i;

	return a2[i]=f2(a2[i]);

}



long long line[1400005],g[400005],h[4000005],num;

int find(long long k){

	int i=1,mid,j=num;

	while(j-i>1){

		mid=(i+j)/2;

		if(k>line[mid])

		     i=mid;

		else j=mid;

		

	}

	if(line[i]==k)return h[i];

	return h[j];

	

}

int main(){

	

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

	for(int q=1;q<=n;q++)a1[q]=a2[q]=q;

	for(int q=1;q<=m1;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a1[f1(i)]=f1(j);

		

	}

	for(int q=1;q<=m2;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a2[f2(i)]=f2(j);

		

	}

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

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		g[q]=ppp;

		

	}

	sort(g+1,g+1+n);

	

	for(int q=1;q<=n;){

		

		line[++num]=g[q];

		int z=1;

		q++;

		while(g[q]==g[q-1]){

			q++;z++;

		}

		h[num]=z;

		if(q>n)break;

	}

	

	

	for(int q=1;q<=1;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf("%d",ans);

		

	}

	for(int q=2;q<=n;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf(" %d",ans);

		

	}

	printf("\n");

	

	return 0;

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

#include <iostream>

#include <algorithm>

#include <map>



using namespace std;



typedef long long LL;



#define MAXN 200010



int n, k, l;

int f1[MAXN], f2[MAXN];

map<pair<int, int> , int> m;



int Find(int *f, int u)

{

    return f[u] ? f[u] = Find(f, f[u]) : u;

}



void Init()

{

    int i, u, v, fu, fv;

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

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

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

        fu = Find(f1, u);

        fv = Find(f1, v);

        if(fu == fv) continue;

        f1[fv] = fu;

    }

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

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

        fu = Find(f2, u);

        fv = Find(f2, v);

        if(fu == fv) continue;

        f2[fv] = fu;

    }

}



void Work()

{

    int i;

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

        ++m[{Find(f1, i), Find(f2, i)}];

    }

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

        printf("%d ", m[{Find(f1, i), Find(f2, i)}]);

    }

    printf("%d\n", m[{Find(f1, i), Find(f2, i)}]);

}



int main()

{

    Init();

    Work();

    return 0;

}


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

#include<string.h>

#include<set>

#include<stdlib.h>

#include<algorithm>

using namespace std;

int n,m1,m2;

int a1[400005],a2[400005];

int f1(int i){

	if(i==a1[i])return i;

	return a1[i]=f1(a1[i]);

}

int f2(int i){

	if(i==a2[i])return i;

	return a2[i]=f2(a2[i]);

}



long long line[1400005],g[400005],h[4000005],num;

int find(long long k){

	int i=1,mid,j=num;

	while(j-i>1){

		mid=(i+j)/2;

		if(k>line[mid])

		     i=mid;

		else j=mid;

		

	}

	if(line[i]==k)return h[i];

	return h[j];

	

}

int main(){

	

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

	for(int q=1;q<=n;q++)a1[q]=a2[q]=q;

	for(int q=1;q<=m1;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a1[f1(i)]=f1(j);

		

	}

	for(int q=1;q<=m2;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a2[f2(i)]=f2(j);

		

	}

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

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		g[q]=ppp;

		

	}

	sort(g+1,g+1+n);

	

	for(int q=1;q<=n;){

		

		line[++num]=g[q];

		int z=1;

		q++;

		while(g[q]==g[q-1]){

			q++;z++;

		}

		h[num]=z;

		if(q>n)break;

	}

	

	

	for(int q=1;q<=1;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf("%d",ans);

		

	}

	for(int q=2;q<=n;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf(" %d",ans);

		

	}

	printf("\n");

	

	return 0;

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

using namespace std;



const int maxn = 200010;



int fa1[maxn], fa2[maxn], r1[maxn], r2[maxn];



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



void kexin_init() {

	for (int i=1; i<=maxn; ++i) {fa1[i] = i; fa2[i] = i;}

	memset(r1, 0, sizeof r1);

	memset(r2, 0, sizeof r2);

}



int kexin_find_road(int x) {

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

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

}

void kexin_Union_road(int x, int y) {

	x = kexin_find_road(x);

	y = kexin_find_road(y);

	if (x == y) return ;

	if (r1[x] < r1[y]) swap(x, y);

	fa1[y] = x;

	if (r1[x] == r1[y]) r1[x]++;

}



int kexin_find_railway(int x) {

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

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

}

void kexin_Union_railway(int x, int y) {

	x = kexin_find_railway(x);

	y = kexin_find_railway(y);

	if (x == y) return ;

	if (r2[x] < r2[y]) swap(x, y);

	fa2[y] = x;

	if (r2[x] == r2[y]) r2[x]++;

}

int main() {

	int n, k, l;

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

	

	kexin_init();

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

		int x, y;

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

		kexin_Union_road(x, y);

	}

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

		int x, y;

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

		kexin_Union_railway(x, y);

	}

	

	mp.clear();



	for (int i=1; i<=n; ++i) mp[make_pair(kexin_find_road(i), kexin_find_railway(i))]++;

	for (int i=1; i<n; ++i) printf("%d ", mp[make_pair(kexin_find_road(i), kexin_find_railway(i))]);

	printf("%d\n", mp[make_pair(kexin_find_road(n), kexin_find_railway(n))]);



	return 0;

}

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

#include<string.h>

#include<set>

#include<stdlib.h>

#include<algorithm>

using namespace std;

int n,m1,m2;

int a1[400005],a2[400005];

int f1(int i){

	if(i==a1[i])return i;

	return a1[i]=f1(a1[i]);

}

int f2(int i){

	if(i==a2[i])return i;

	return a2[i]=f2(a2[i]);

}



long long line[1400005],g[400005],h[4000005],num;

int find(long long k){

	int i=1,mid,j=num;

	while(j-i>1){

		mid=(i+j)/2;

		if(k>line[mid])

		     i=mid;

		else j=mid;

		

	}

	if(line[i]==k)return h[i];

	return h[j];

	

}

int main(){

	

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

	for(int q=1;q<=n;q++)a1[q]=a2[q]=q;

	for(int q=1;q<=m1;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a1[f1(i)]=f1(j);

		

	}

	for(int q=1;q<=m2;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a2[f2(i)]=f2(j);

		

	}

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

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		g[q]=ppp;

		

	}

	sort(g+1,g+1+n);

	

	for(int q=1;q<=n;){

		

		line[++num]=g[q];

		int z=1;

		q++;

		while(g[q]==g[q-1]){

			q++;z++;

		}

		h[num]=z;

		if(q>n)break;

	}

	

	

	for(int q=1;q<=1;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf("%d",ans);

		

	}

	for(int q=2;q<=n;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf(" %d",ans);

		

	}

	printf("\n");

	

	return 0;

}
// Slower C++ solution:
//created by missever



#include<bits/stdc++.h>

#define MAX 1000000007

using namespace std;

typedef long long LL;



typedef pair<int,int> P;

const int maxn = 200005;

int p1[maxn],p2[maxn],t[maxn];

map<P,int> q;



int ff(int f[],int x)

{

    if(f[x] != x) f[x] = ff(f,f[x]);

    return f[x];

}



int main(){

    int n,k,l,i,u,v,a,b;

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

    for(i = 0;i <= n; i++) p1[i] = p2[i] = i;

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

    {

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

        a = ff(p1,u);

        b = ff(p1,v);

        if(a != b) p1[a] = b;

    }

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

    {

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

        a = ff(p2,u);

        b = ff(p2,v);

        if(a != b) p2[a] = b;

    }

    for(i = 1;i <= n; i++) q[P(ff(p1,i),ff(p2,i))]++;

    for(i = 1;i <= n; i++) printf("%d%c",q[P(ff(p1,i),ff(p2,i))]," \n"[i == n]);

    return 0;

}


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

#include<string.h>

#include<set>

#include<stdlib.h>

#include<algorithm>

using namespace std;

int n,m1,m2;

int a1[400005],a2[400005];

int f1(int i){

	if(i==a1[i])return i;

	return a1[i]=f1(a1[i]);

}

int f2(int i){

	if(i==a2[i])return i;

	return a2[i]=f2(a2[i]);

}



long long line[1400005],g[400005],h[4000005],num;

int find(long long k){

	int i=1,mid,j=num;

	while(j-i>1){

		mid=(i+j)/2;

		if(k>line[mid])

		     i=mid;

		else j=mid;

		

	}

	if(line[i]==k)return h[i];

	return h[j];

	

}

int main(){

	

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

	for(int q=1;q<=n;q++)a1[q]=a2[q]=q;

	for(int q=1;q<=m1;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a1[f1(i)]=f1(j);

		

	}

	for(int q=1;q<=m2;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a2[f2(i)]=f2(j);

		

	}

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

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		g[q]=ppp;

		

	}

	sort(g+1,g+1+n);

	

	for(int q=1;q<=n;){

		

		line[++num]=g[q];

		int z=1;

		q++;

		while(g[q]==g[q-1]){

			q++;z++;

		}

		h[num]=z;

		if(q>n)break;

	}

	

	

	for(int q=1;q<=1;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf("%d",ans);

		

	}

	for(int q=2;q<=n;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf(" %d",ans);

		

	}

	printf("\n");

	

	return 0;

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

using namespace std;

map<pair<int,int>,int>v;

const int MAX = 2e5 +5;

int rail[MAX],road[MAX];



int road_f(int x) {

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

  else return road[x] = road_f(road[x]);

}

int rail_f(int x) {

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

  else return rail[x] = rail_f(rail[x]);

}

int main() {

  int n,k,l,x,y;

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

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

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

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

    x = road_f(x),y = road_f(y);

    road[x] = y;

  }

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

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

    x = rail_f(x),y = rail_f(y);

    rail[x] = y;

  }

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

    road[i] = road_f(i);

    rail[i] = rail_f(i);

    v[make_pair(road[i],rail[i])]++;

  }

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

    printf("%d ",v[make_pair(road[i],rail[i])]);

  }

  printf("%d\n",v[make_pair(road[n],rail[n])]);

}

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

#include<string.h>

#include<set>

#include<stdlib.h>

#include<algorithm>

using namespace std;

int n,m1,m2;

int a1[400005],a2[400005];

int f1(int i){

	if(i==a1[i])return i;

	return a1[i]=f1(a1[i]);

}

int f2(int i){

	if(i==a2[i])return i;

	return a2[i]=f2(a2[i]);

}



long long line[1400005],g[400005],h[4000005],num;

int find(long long k){

	int i=1,mid,j=num;

	while(j-i>1){

		mid=(i+j)/2;

		if(k>line[mid])

		     i=mid;

		else j=mid;

		

	}

	if(line[i]==k)return h[i];

	return h[j];

	

}

int main(){

	

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

	for(int q=1;q<=n;q++)a1[q]=a2[q]=q;

	for(int q=1;q<=m1;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a1[f1(i)]=f1(j);

		

	}

	for(int q=1;q<=m2;q++){

		int i,j;

		scanf("%d%d",&i,&j);

		a2[f2(i)]=f2(j);

		

	}

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

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		g[q]=ppp;

		

	}

	sort(g+1,g+1+n);

	

	for(int q=1;q<=n;){

		

		line[++num]=g[q];

		int z=1;

		q++;

		while(g[q]==g[q-1]){

			q++;z++;

		}

		h[num]=z;

		if(q>n)break;

	}

	

	

	for(int q=1;q<=1;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf("%d",ans);

		

	}

	for(int q=2;q<=n;q++){

		int i1=f1(q),i2=f2(q);

		long long ppp=i1;

		ppp=ppp*1000000+i2;

		int ans=find(ppp);

		printf(" %d",ans);

		

	}

	printf("\n");

	

	return 0;

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

using namespace std;



const int maxn = 200010;



int fa1[maxn], fa2[maxn], r1[maxn], r2[maxn];



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



void kexin_init() {

	for (int i=1; i<=maxn; ++i) {fa1[i] = i; fa2[i] = i;}

	memset(r1, 0, sizeof r1);

	memset(r2, 0, sizeof r2);

}



int kexin_find_road(int x) {

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

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

}

void kexin_Union_road(int x, int y) {

	x = kexin_find_road(x);

	y = kexin_find_road(y);

	if (x == y) return ;

	if (r1[x] < r1[y]) swap(x, y);

	fa1[y] = x;

	if (r1[x] == r1[y]) r1[x]++;

}



int kexin_find_railway(int x) {

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

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

}

void kexin_Union_railway(int x, int y) {

	x = kexin_find_railway(x);

	y = kexin_find_railway(y);

	if (x == y) return ;

	if (r2[x] < r2[y]) swap(x, y);

	fa2[y] = x;

	if (r2[x] == r2[y]) r2[x]++;

}

int main() {

	int n, k, l;

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

	

	kexin_init();

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

		int x, y;

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

		kexin_Union_road(x, y);

	}

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

		int x, y;

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

		kexin_Union_railway(x, y);

	}

	

	mp.clear();



	for (int i=1; i<=n; ++i) mp[make_pair(kexin_find_road(i), kexin_find_railway(i))]++;

	for (int i=1; i<n; ++i) printf("%d ", mp[make_pair(kexin_find_road(i), kexin_find_railway(i))]);

	printf("%d\n", mp[make_pair(kexin_find_road(n), kexin_find_railway(n))]);



	return 0;

}

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

#include <cstdlib>

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

typedef long long LL;

inline int read() {

	int f=1,x=0; char ch=getchar();

	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return x*f;

}



const int MAXN=200005;

int n,m,r,tot,v[MAXN],f[MAXN],ans[MAXN];

struct List{

	int l,lt[MAXN],nt[MAXN<<1],v[MAXN<<1];

	void clear() { l=0; memset(lt,0,sizeof(lt)); }

	void addedge(int x,int y) { nt[++l]=lt[x]; lt[x]=l; v[l]=y; }

}E;

struct Data{

	int x,y;

	bool operator <(const Data &B)const { return x<B.x; }

}A[MAXN];

int ask(int x) { if (f[x]==x) return x; f[x]=ask(f[x]); return f[x]; }

void dfs(int x) {

	v[x]=1; A[++tot].x=ask(x); A[tot].y=x;

	for (int i=E.lt[x];i;i=E.nt[i]) if (!v[E.v[i]]) dfs(E.v[i]);

}

int main() {

	int i,j,k,l;

	n=read(); m=read(); r=read();

	for (i=1;i<=n;++i) f[i]=i; E.clear();

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

		j=read(); k=read();

		E.addedge(j,k); E.addedge(k,j);

	}

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

		j=ask(read()); k=ask(read());

		if (j!=k) f[j]=k;

	}

	memset(v,0,sizeof(v));

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

	if (!v[i]) {

		tot=0; dfs(i); sort(A+1,A+1+tot);

		for (j=1;j<=tot;j=k+1) {

			for (k=j;k<tot&&A[k+1].x==A[j].x;++k);

			for (l=j;l<=k;++l) ans[A[l].y]=k-j+1;

		}

	}

	for (i=1;i<n;++i) printf("%d ",ans[i]); printf("%d\n",ans[n]);

	return 0;

}



/*

4 3 1

1 2

2 3

3 4

2 3



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

#include <map>

#include <vector>

using namespace std;



const int N = 2e5 + 5;

int pa1[N], pa2[N];

int find(int* p, int v) { return v == p[v] ? v : p[v] = find(p, p[v]); }

void unite(int* p, int a, int b) { p[find(p, b)] = find(p, a); }



typedef long long LL;

int n, k, l;

// vector<int> e1[N], e2[N];



map<LL, int> mp;



int main() {

#ifdef D

    freopen("a.in", "r", stdin);

#endif

    for (int i = 0; i < N; i++) {

        pa1[i] = pa2[i] = i;

    }

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

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

        int a, b;

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

        unite(pa1, a, b);

        // e1[a].push_back(b);

        // e1[b].push_back(a);

    }

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

        int a, b;

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

        unite(pa2, a, b);

        // e2[a].push_back(b);

        // e2[b].push_back(a);

    }



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

        mp[find(pa1, i) * (LL)(n + 1) + find(pa2, i)] += 1;

    }



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

        printf("%d ", mp[find(pa1, i) * (LL)(n + 1) + find(pa2, i)]);

    }

    puts("");



    return 0;

}


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

#include <iostream>

#include <algorithm>

#define N 200007

using namespace std;

int n,k,l,p,q,r,s,f1[N],f2[N],a[N],cnt[N],ans[N];

int find1(int x){return f1[x]==x ? x:f1[x]=find1(f1[x]);}

int find2(int x){return f2[x]==x ? x:f2[x]=find2(f2[x]);}

bool cmp(int x,int y){return f1[x]<f1[y];}

int main(){

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

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

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

		scanf("%d%d",&p,&q);

		f1[find1(p)]=find1(q);

	}

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

		scanf("%d%d",&r,&s);

		f2[find2(r)]=find2(s);

	}

	for(int i=1;i<=n;++i)f1[i]=find1(i),f2[i]=find2(i);

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

	sort(a+1,a+n+1,cmp);

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

		int j=i;

		while(j<n && f1[a[j+1]]==f1[a[j]])++j;

		for(int t=i;t<=j;++t)++cnt[f2[a[t]]];

		for(int t=i;t<=j;++t)ans[a[t]]=cnt[f2[a[t]]];

		for(int t=i;t<=j;++t)--cnt[f2[a[t]]];

		i=j;

	}

	for(int i=1;i<=n;++i)printf("%d ",ans[i]);

}