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

#include <cstdio>

#include <algorithm>

#include <vector>

#include <stack>

#include <queue>

#include <map>

#include <set>

#include <string>

#include <cstring>

#include <bitset>

#define ll long long

#define rep(x,n) for(ll (x)=0;(x)<n;(x)++)

#define rep1(x,n) for(ll (x)=1;(x)<=n;(x)++)

using namespace std;



const ll N=200002;



struct node

{

    int id,pa1,pa2;

    node(int _id=0,int _pa1=0,int _pa2=0)

    {

        id=_id;pa1=_pa1;pa2=_pa2;

    }

    bool operator < (const node b) const

    {

        return pa1<b.pa1;

    }

};



int n,pa1[N],pa2[N],ans[N]={0};

vector<node> S[N];



int fpa1(int x)

{

    return pa1[x]==x?x:pa1[x]=fpa1(pa1[x]);

}



int fpa2(int x)

{

    return pa2[x]==x?x:pa2[x]=fpa2(pa2[x]);

}



int main()

{

    #ifdef LOCAL

        freopen("C_data","r",stdin);

    #endif

    int k,l,a,b;

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

    rep1(i,n) pa1[i]=i,pa2[i]=i;

    while(k--)

    {

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

        if(fpa1(b)!=fpa1(a))

            pa1[fpa1(b)]=fpa1(a);

    }

    while(l--)

    {

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

        if(fpa2(b)!=fpa2(a))

            pa2[fpa2(b)]=fpa2(a);

    }

    rep1(i,n)

    {

        S[fpa2(i)].push_back(node(i,fpa1(i),fpa2(i)));

    }

    rep1(i,n)

    {

        sort(S[i].begin(),S[i].end());

        int st=0;

        while(st<S[i].size())

        {

            int t=st,cnt=1;

            while(t+1<S[i].size() && S[i][t+1].pa1==S[i][t].pa1) t++,cnt++;

            for(int j=st;j<=t;j++)

            {

                ans[S[i][j].id]=cnt;

            }

            st=t+1;

        }

    }

    rep1(i,n) cout<<ans[i]<<' ';

    cout<<endl;

    return 0;

}


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

#define sz(x) ((int)(x).size())

#define rep(i,a,b) for (int i=(a); i<(b); i++)

#define per(i,a,b) for (int i=(b-1); i>=(a); i--)

#define debug(x) cout << #x << " => " << x << endl

using namespace std;



#define fi first

#define se second

#define mp make_pair

typedef pair<int,int> pii;



#define pb push_back

typedef vector<int> vi;



typedef long long ll;

typedef long double ld;



const int MAX_N = 7 + 200000;

///----------------------------------------------

struct UF {

	static const int UF_N = MAX_N;

	int far[UF_N];

	void init() { rep(i,0,UF_N) far[i]=i; }

	int getf(int d) { return far[d]==d ? d : far[d]=getf(far[d]); }

	bool same(int a,int b) { return getf(a)==getf(b); }

	void comb(int a,int b) {

		if (same(a=getf(a),b=getf(b))) return;

		far[a]=b;

	}

}	uf1,uf2;

int main() {

	

	///read

	int n,m1,m2; cin>>n>>m1>>m2;

	

	///prework

	uf1.init();

	rep(i,0,m1) {

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

		uf1.comb(a,b);

	}

	uf2.init();

	rep(i,0,m2) {

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

		uf2.comb(a,b);

	}

	map<pii,int> M;

	rep(i,1,n+1) M[mp(uf1.getf(i),uf2.getf(i))]++;

	

	///work

	rep(i,1,n+1) {

		printf("%d ",M[mp(uf1.getf(i),uf2.getf(i))]);

	}





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

#include<cstring>

#include<algorithm>

struct abc {

	int aa, bb, cc;

	bool operator < (const abc&T) const {

		return(aa < T.aa || (aa == T.aa && bb < T.bb) || (aa == T.aa && bb == T.bb && cc < T.cc));

	}

	bool operator == (const abc&T) const {

		return(aa == T.aa && bb == T.bb);

	}

} ans[200005];

using namespace std;

int N, KK, LL, i, j, k, l, m, n, pt1[200005], pt2[200005], s1[200005], s2[200005], z;

int sz[200005], ans2[200005];

int find1(int aa) {

	if(pt1[aa] != aa) 

		pt1[aa] = find1(pt1[aa]);

	return(pt1[aa]);

}

int find2(int bb) {

	if(pt2[bb] != bb) 

		pt2[bb] = find2(pt2[bb]);

	return(pt2[bb]);

}

int main() {

	scanf("%d%d%d", &N, &KK, &LL);

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

		pt1[i] = i;

		pt2[i] = i;

		s1[i] = 1;

		s2[i] = 1;

	}

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

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

		if(find1(j) == find1(l)) continue;

		s1[find1(l)] += s1[find1(j)];

		pt1[find1(j)] = find1(l);

	}

	

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

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

		if(find2(j) == find2(l)) continue;

		s2[find2(l)] += s2[find2(j)];

		pt2[find2(j)] = find2(l);

	}

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

		pt1[i] = find1(i);

		pt2[i] = find2(i);

		ans[i].aa = pt1[i];

		ans[i].bb = pt2[i];

		ans[i].cc = i;

	}

//	for(i = 1; i <= N; i++) printf("%d %d\n", pt1[i], pt2[i]);

	

	sort(ans + 1, ans + N + 1);

	sz[1] = 1;

	for(i = 2; i <= N; i++) if(ans[i] == ans[i - 1]) {

		sz[i] = sz[i - 1] + 1;

	} else {

		sz[i] = 1;

	}

	for(i = N - 1; i >= 1; i--) 

	if(ans[i] == ans[i + 1]) sz[i] = sz[i + 1];

	

	//for(i = 1; i <= N; i++) printf("%d %d %d %d\n", ans[i].aa, ans[i].bb, ans[i].cc, sz[i]);

	

	for(i = 1; i <= N; i++) ans2[ans[i].cc] = sz[i];

	

	for(i = 1; i < N; i++) printf("%d ", ans2[i]);

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

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

#include<cstring>

#include<algorithm>

struct abc {

	int aa, bb, cc;

	bool operator < (const abc&T) const {

		return(aa < T.aa || (aa == T.aa && bb < T.bb) || (aa == T.aa && bb == T.bb && cc < T.cc));

	}

	bool operator == (const abc&T) const {

		return(aa == T.aa && bb == T.bb);

	}

} ans[200005];

using namespace std;

int N, KK, LL, i, j, k, l, m, n, pt1[200005], pt2[200005], s1[200005], s2[200005], z;

int sz[200005], ans2[200005];

int find1(int aa) {

	if(pt1[aa] != aa) 

		pt1[aa] = find1(pt1[aa]);

	return(pt1[aa]);

}

int find2(int bb) {

	if(pt2[bb] != bb) 

		pt2[bb] = find2(pt2[bb]);

	return(pt2[bb]);

}

int main() {

	scanf("%d%d%d", &N, &KK, &LL);

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

		pt1[i] = i;

		pt2[i] = i;

		s1[i] = 1;

		s2[i] = 1;

	}

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

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

		if(find1(j) == find1(l)) continue;

		s1[find1(l)] += s1[find1(j)];

		pt1[find1(j)] = find1(l);

	}

	

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

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

		if(find2(j) == find2(l)) continue;

		s2[find2(l)] += s2[find2(j)];

		pt2[find2(j)] = find2(l);

	}

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

		pt1[i] = find1(i);

		pt2[i] = find2(i);

		ans[i].aa = pt1[i];

		ans[i].bb = pt2[i];

		ans[i].cc = i;

	}

//	for(i = 1; i <= N; i++) printf("%d %d\n", pt1[i], pt2[i]);

	

	sort(ans + 1, ans + N + 1);

	sz[1] = 1;

	for(i = 2; i <= N; i++) if(ans[i] == ans[i - 1]) {

		sz[i] = sz[i - 1] + 1;

	} else {

		sz[i] = 1;

	}

	for(i = N - 1; i >= 1; i--) 

	if(ans[i] == ans[i + 1]) sz[i] = sz[i + 1];

	

	//for(i = 1; i <= N; i++) printf("%d %d %d %d\n", ans[i].aa, ans[i].bb, ans[i].cc, sz[i]);

	

	for(i = 1; i <= N; i++) ans2[ans[i].cc] = sz[i];

	

	for(i = 1; i < N; i++) printf("%d ", ans2[i]);

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

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

#include<cstring>

#include<algorithm>

struct abc {

	int aa, bb, cc;

	bool operator < (const abc&T) const {

		return(aa < T.aa || (aa == T.aa && bb < T.bb) || (aa == T.aa && bb == T.bb && cc < T.cc));

	}

	bool operator == (const abc&T) const {

		return(aa == T.aa && bb == T.bb);

	}

} ans[200005];

using namespace std;

int N, KK, LL, i, j, k, l, m, n, pt1[200005], pt2[200005], s1[200005], s2[200005], z;

int sz[200005], ans2[200005];

int find1(int aa) {

	if(pt1[aa] != aa) 

		pt1[aa] = find1(pt1[aa]);

	return(pt1[aa]);

}

int find2(int bb) {

	if(pt2[bb] != bb) 

		pt2[bb] = find2(pt2[bb]);

	return(pt2[bb]);

}

int main() {

	scanf("%d%d%d", &N, &KK, &LL);

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

		pt1[i] = i;

		pt2[i] = i;

		s1[i] = 1;

		s2[i] = 1;

	}

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

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

		if(find1(j) == find1(l)) continue;

		s1[find1(l)] += s1[find1(j)];

		pt1[find1(j)] = find1(l);

	}

	

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

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

		if(find2(j) == find2(l)) continue;

		s2[find2(l)] += s2[find2(j)];

		pt2[find2(j)] = find2(l);

	}

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

		pt1[i] = find1(i);

		pt2[i] = find2(i);

		ans[i].aa = pt1[i];

		ans[i].bb = pt2[i];

		ans[i].cc = i;

	}

//	for(i = 1; i <= N; i++) printf("%d %d\n", pt1[i], pt2[i]);

	

	sort(ans + 1, ans + N + 1);

	sz[1] = 1;

	for(i = 2; i <= N; i++) if(ans[i] == ans[i - 1]) {

		sz[i] = sz[i - 1] + 1;

	} else {

		sz[i] = 1;

	}

	for(i = N - 1; i >= 1; i--) 

	if(ans[i] == ans[i + 1]) sz[i] = sz[i + 1];

	

	//for(i = 1; i <= N; i++) printf("%d %d %d %d\n", ans[i].aa, ans[i].bb, ans[i].cc, sz[i]);

	

	for(i = 1; i <= N; i++) ans2[ans[i].cc] = sz[i];

	

	for(i = 1; i < N; i++) printf("%d ", ans2[i]);

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

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

#include<cstring>

#include<algorithm>

struct abc {

	int aa, bb, cc;

	bool operator < (const abc&T) const {

		return(aa < T.aa || (aa == T.aa && bb < T.bb) || (aa == T.aa && bb == T.bb && cc < T.cc));

	}

	bool operator == (const abc&T) const {

		return(aa == T.aa && bb == T.bb);

	}

} ans[200005];

using namespace std;

int N, KK, LL, i, j, k, l, m, n, pt1[200005], pt2[200005], s1[200005], s2[200005], z;

int sz[200005], ans2[200005];

int find1(int aa) {

	if(pt1[aa] != aa) 

		pt1[aa] = find1(pt1[aa]);

	return(pt1[aa]);

}

int find2(int bb) {

	if(pt2[bb] != bb) 

		pt2[bb] = find2(pt2[bb]);

	return(pt2[bb]);

}

int main() {

	scanf("%d%d%d", &N, &KK, &LL);

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

		pt1[i] = i;

		pt2[i] = i;

		s1[i] = 1;

		s2[i] = 1;

	}

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

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

		if(find1(j) == find1(l)) continue;

		s1[find1(l)] += s1[find1(j)];

		pt1[find1(j)] = find1(l);

	}

	

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

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

		if(find2(j) == find2(l)) continue;

		s2[find2(l)] += s2[find2(j)];

		pt2[find2(j)] = find2(l);

	}

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

		pt1[i] = find1(i);

		pt2[i] = find2(i);

		ans[i].aa = pt1[i];

		ans[i].bb = pt2[i];

		ans[i].cc = i;

	}

//	for(i = 1; i <= N; i++) printf("%d %d\n", pt1[i], pt2[i]);

	

	sort(ans + 1, ans + N + 1);

	sz[1] = 1;

	for(i = 2; i <= N; i++) if(ans[i] == ans[i - 1]) {

		sz[i] = sz[i - 1] + 1;

	} else {

		sz[i] = 1;

	}

	for(i = N - 1; i >= 1; i--) 

	if(ans[i] == ans[i + 1]) sz[i] = sz[i + 1];

	

	//for(i = 1; i <= N; i++) printf("%d %d %d %d\n", ans[i].aa, ans[i].bb, ans[i].cc, sz[i]);

	

	for(i = 1; i <= N; i++) ans2[ans[i].cc] = sz[i];

	

	for(i = 1; i < N; i++) printf("%d ", ans2[i]);

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

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

#include<cstring>

#include<algorithm>

struct abc {

	int aa, bb, cc;

	bool operator < (const abc&T) const {

		return(aa < T.aa || (aa == T.aa && bb < T.bb) || (aa == T.aa && bb == T.bb && cc < T.cc));

	}

	bool operator == (const abc&T) const {

		return(aa == T.aa && bb == T.bb);

	}

} ans[200005];

using namespace std;

int N, KK, LL, i, j, k, l, m, n, pt1[200005], pt2[200005], s1[200005], s2[200005], z;

int sz[200005], ans2[200005];

int find1(int aa) {

	if(pt1[aa] != aa) 

		pt1[aa] = find1(pt1[aa]);

	return(pt1[aa]);

}

int find2(int bb) {

	if(pt2[bb] != bb) 

		pt2[bb] = find2(pt2[bb]);

	return(pt2[bb]);

}

int main() {

	scanf("%d%d%d", &N, &KK, &LL);

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

		pt1[i] = i;

		pt2[i] = i;

		s1[i] = 1;

		s2[i] = 1;

	}

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

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

		if(find1(j) == find1(l)) continue;

		s1[find1(l)] += s1[find1(j)];

		pt1[find1(j)] = find1(l);

	}

	

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

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

		if(find2(j) == find2(l)) continue;

		s2[find2(l)] += s2[find2(j)];

		pt2[find2(j)] = find2(l);

	}

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

		pt1[i] = find1(i);

		pt2[i] = find2(i);

		ans[i].aa = pt1[i];

		ans[i].bb = pt2[i];

		ans[i].cc = i;

	}

//	for(i = 1; i <= N; i++) printf("%d %d\n", pt1[i], pt2[i]);

	

	sort(ans + 1, ans + N + 1);

	sz[1] = 1;

	for(i = 2; i <= N; i++) if(ans[i] == ans[i - 1]) {

		sz[i] = sz[i - 1] + 1;

	} else {

		sz[i] = 1;

	}

	for(i = N - 1; i >= 1; i--) 

	if(ans[i] == ans[i + 1]) sz[i] = sz[i + 1];

	

	//for(i = 1; i <= N; i++) printf("%d %d %d %d\n", ans[i].aa, ans[i].bb, ans[i].cc, sz[i]);

	

	for(i = 1; i <= N; i++) ans2[ans[i].cc] = sz[i];

	

	for(i = 1; i < N; i++) printf("%d ", ans2[i]);

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

}
// Slower C++ solution:
#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]);

}

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

#include<cstring>

#include<algorithm>

struct abc {

	int aa, bb, cc;

	bool operator < (const abc&T) const {

		return(aa < T.aa || (aa == T.aa && bb < T.bb) || (aa == T.aa && bb == T.bb && cc < T.cc));

	}

	bool operator == (const abc&T) const {

		return(aa == T.aa && bb == T.bb);

	}

} ans[200005];

using namespace std;

int N, KK, LL, i, j, k, l, m, n, pt1[200005], pt2[200005], s1[200005], s2[200005], z;

int sz[200005], ans2[200005];

int find1(int aa) {

	if(pt1[aa] != aa) 

		pt1[aa] = find1(pt1[aa]);

	return(pt1[aa]);

}

int find2(int bb) {

	if(pt2[bb] != bb) 

		pt2[bb] = find2(pt2[bb]);

	return(pt2[bb]);

}

int main() {

	scanf("%d%d%d", &N, &KK, &LL);

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

		pt1[i] = i;

		pt2[i] = i;

		s1[i] = 1;

		s2[i] = 1;

	}

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

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

		if(find1(j) == find1(l)) continue;

		s1[find1(l)] += s1[find1(j)];

		pt1[find1(j)] = find1(l);

	}

	

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

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

		if(find2(j) == find2(l)) continue;

		s2[find2(l)] += s2[find2(j)];

		pt2[find2(j)] = find2(l);

	}

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

		pt1[i] = find1(i);

		pt2[i] = find2(i);

		ans[i].aa = pt1[i];

		ans[i].bb = pt2[i];

		ans[i].cc = i;

	}

//	for(i = 1; i <= N; i++) printf("%d %d\n", pt1[i], pt2[i]);

	

	sort(ans + 1, ans + N + 1);

	sz[1] = 1;

	for(i = 2; i <= N; i++) if(ans[i] == ans[i - 1]) {

		sz[i] = sz[i - 1] + 1;

	} else {

		sz[i] = 1;

	}

	for(i = N - 1; i >= 1; i--) 

	if(ans[i] == ans[i + 1]) sz[i] = sz[i + 1];

	

	//for(i = 1; i <= N; i++) printf("%d %d %d %d\n", ans[i].aa, ans[i].bb, ans[i].cc, sz[i]);

	

	for(i = 1; i <= N; i++) ans2[ans[i].cc] = sz[i];

	

	for(i = 1; i < N; i++) printf("%d ", ans2[i]);

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

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

#include <cstring>

#include <algorithm>

#include <vector>

#define ll long long

using namespace std;



const int maxn = 200010;

int n, m1, m2, u, v;

int f1[maxn], f2[maxn], vis[maxn], cnt[maxn], res[maxn];

vector <int> G[maxn];



int Find1 (int x) {

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

	return f1[x] = Find1(f1[x]);

}



int Find2 (int x) {

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

	return f2[x] = Find2(f2[x]);

}



int main () {

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

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

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

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

        f1[Find1(u)] = Find1(v);

	}

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

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

        f2[Find2(u)] = Find2(v);

	}

    for (int i = 1; i <= n; i++) G[Find1(i)].push_back(i);

    for (int i = 1; i <= n; i++) if(G[i].size()) {

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

            int t = Find2(G[i][j]);

            if (vis[t] != i) {

                vis[t] = i;

                cnt[t] = 0;

            }

            cnt[t]++;

        }

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

            int t = Find2(G[i][j]);

            res[G[i][j]] = cnt[t];

        }

    }

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

	return 0;

}


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

#include<cstring>

#include<algorithm>

struct abc {

	int aa, bb, cc;

	bool operator < (const abc&T) const {

		return(aa < T.aa || (aa == T.aa && bb < T.bb) || (aa == T.aa && bb == T.bb && cc < T.cc));

	}

	bool operator == (const abc&T) const {

		return(aa == T.aa && bb == T.bb);

	}

} ans[200005];

using namespace std;

int N, KK, LL, i, j, k, l, m, n, pt1[200005], pt2[200005], s1[200005], s2[200005], z;

int sz[200005], ans2[200005];

int find1(int aa) {

	if(pt1[aa] != aa) 

		pt1[aa] = find1(pt1[aa]);

	return(pt1[aa]);

}

int find2(int bb) {

	if(pt2[bb] != bb) 

		pt2[bb] = find2(pt2[bb]);

	return(pt2[bb]);

}

int main() {

	scanf("%d%d%d", &N, &KK, &LL);

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

		pt1[i] = i;

		pt2[i] = i;

		s1[i] = 1;

		s2[i] = 1;

	}

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

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

		if(find1(j) == find1(l)) continue;

		s1[find1(l)] += s1[find1(j)];

		pt1[find1(j)] = find1(l);

	}

	

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

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

		if(find2(j) == find2(l)) continue;

		s2[find2(l)] += s2[find2(j)];

		pt2[find2(j)] = find2(l);

	}

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

		pt1[i] = find1(i);

		pt2[i] = find2(i);

		ans[i].aa = pt1[i];

		ans[i].bb = pt2[i];

		ans[i].cc = i;

	}

//	for(i = 1; i <= N; i++) printf("%d %d\n", pt1[i], pt2[i]);

	

	sort(ans + 1, ans + N + 1);

	sz[1] = 1;

	for(i = 2; i <= N; i++) if(ans[i] == ans[i - 1]) {

		sz[i] = sz[i - 1] + 1;

	} else {

		sz[i] = 1;

	}

	for(i = N - 1; i >= 1; i--) 

	if(ans[i] == ans[i + 1]) sz[i] = sz[i + 1];

	

	//for(i = 1; i <= N; i++) printf("%d %d %d %d\n", ans[i].aa, ans[i].bb, ans[i].cc, sz[i]);

	

	for(i = 1; i <= N; i++) ans2[ans[i].cc] = sz[i];

	

	for(i = 1; i < N; i++) printf("%d ", ans2[i]);

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

}