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.192688951378382x):
#include<bits/stdc++.h>

using namespace std;

int bcj1[200010],bcj2[200010];

int father1(int k)

{

    return bcj1[k]==k?k:bcj1[k]=father1(bcj1[k]);

}

void join1(int x,int y)

{

    int fa,fb;

    fa=father1(x);fb=father1(y);

    bcj1[fb]=fa;

}

int father2(int k)

{

    return bcj2[k]==k?k:bcj2[k]=father2(bcj2[k]);

}

void join2(int x,int y)

{

    int fa,fb;

    fa=father2(x);fb=father2(y);

    bcj2[fb]=fa;

}

struct haha

{

    int p,q,no,ans;

}pp[200010];

bool cmp1(haha a,haha b)

{

    if (a.p==b.p) return a.q<b.q;

    return a.p<b.p;

}

bool cmp2(haha a,haha b)

{

    return a.no<b.no;

}

int main()

{

    int n,k,l,a,b,i,j,m,cnt;

    cin>>n>>k>>l;

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

    {

        bcj1[i]=bcj2[i]=i;

        pp[i].ans=0;pp[i].no=i;

    }

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

    {

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

        join1(a,b);

    }

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

    {

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

        join2(a,b);

    }

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

    {

        bcj1[i]=father1(bcj1[i]);

        pp[i].p=bcj1[i];

        bcj2[i]=father2(bcj2[i]);

        pp[i].q=bcj2[i];

    }

    sort(pp+1,pp+1+n,cmp1);cnt=0;

    pp[0].p=pp[0].q=0;j=1;

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

    {

        if (i<=n && pp[i].p==pp[i-1].p && pp[i].q==pp[i-1].q) continue;

        for(m=j;m<=i-1;m++)

            pp[m].ans=i-j;

        j=i;

    }

    sort(pp+1,pp+1+n,cmp2);

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

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

    cout<<endl;

    return 0;

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



*/


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

using namespace std;

int bcj1[200010],bcj2[200010];

int father1(int k)

{

    return bcj1[k]==k?k:bcj1[k]=father1(bcj1[k]);

}

void join1(int x,int y)

{

    int fa,fb;

    fa=father1(x);fb=father1(y);

    bcj1[fb]=fa;

}

int father2(int k)

{

    return bcj2[k]==k?k:bcj2[k]=father2(bcj2[k]);

}

void join2(int x,int y)

{

    int fa,fb;

    fa=father2(x);fb=father2(y);

    bcj2[fb]=fa;

}

struct haha

{

    int p,q,no,ans;

}pp[200010];

bool cmp1(haha a,haha b)

{

    if (a.p==b.p) return a.q<b.q;

    return a.p<b.p;

}

bool cmp2(haha a,haha b)

{

    return a.no<b.no;

}

int main()

{

    int n,k,l,a,b,i,j,m,cnt;

    cin>>n>>k>>l;

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

    {

        bcj1[i]=bcj2[i]=i;

        pp[i].ans=0;pp[i].no=i;

    }

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

    {

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

        join1(a,b);

    }

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

    {

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

        join2(a,b);

    }

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

    {

        bcj1[i]=father1(bcj1[i]);

        pp[i].p=bcj1[i];

        bcj2[i]=father2(bcj2[i]);

        pp[i].q=bcj2[i];

    }

    sort(pp+1,pp+1+n,cmp1);cnt=0;

    pp[0].p=pp[0].q=0;j=1;

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

    {

        if (i<=n && pp[i].p==pp[i-1].p && pp[i].q==pp[i-1].q) continue;

        for(m=j;m<=i-1;m++)

            pp[m].ans=i-j;

        j=i;

    }

    sort(pp+1,pp+1+n,cmp2);

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

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

    cout<<endl;

    return 0;

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

#include<algorithm>

#include<iostream>

#include<cstring>

#include<vector>

#include<cmath>

#include<map>

#include<set>

#include<queue>

using namespace std;

typedef long long ll;

const int N=2e5+10;

int a[N],b[N];

vector<int>v[N];

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

queue<int>q;

int main()

{

    int n,k,l,i,j;

    cin>>n>>k>>l;

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

    {

        int x,y;

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

        v[x].push_back(y);

        v[y].push_back(x);

    }

    int cnt=0;

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

    if(a[i]==0)

    {

        a[i]=++cnt;

        q.push(i);

        while(!q.empty())

        {

            int x=q.front();

            for(j=0;j<v[x].size();j++)

            if(a[v[x][j]]==0)

            {

                a[v[x][j]]=cnt;

                q.push(v[x][j]);

            }

            q.pop();

        }

    }

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

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

    {

        int x,y;

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

        v[x].push_back(y);

        v[y].push_back(x);

    }

    cnt=0;

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

    if(b[i]==0)

    {

        b[i]=++cnt;

        q.push(i);

        while(!q.empty())

        {

            int x=q.front();

            for(j=0;j<v[x].size();j++)

            if(b[v[x][j]]==0)

            {

                b[v[x][j]]=cnt;

                q.push(v[x][j]);

            }

            q.pop();

        }

    }

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

        mp[make_pair(a[i],b[i])]++;

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

        printf("%d ",mp[make_pair(a[i],b[i])]);

	return 0;

}


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

using namespace std;

int bcj1[200010],bcj2[200010];

int father1(int k)

{

    return bcj1[k]==k?k:bcj1[k]=father1(bcj1[k]);

}

void join1(int x,int y)

{

    int fa,fb;

    fa=father1(x);fb=father1(y);

    bcj1[fb]=fa;

}

int father2(int k)

{

    return bcj2[k]==k?k:bcj2[k]=father2(bcj2[k]);

}

void join2(int x,int y)

{

    int fa,fb;

    fa=father2(x);fb=father2(y);

    bcj2[fb]=fa;

}

struct haha

{

    int p,q,no,ans;

}pp[200010];

bool cmp1(haha a,haha b)

{

    if (a.p==b.p) return a.q<b.q;

    return a.p<b.p;

}

bool cmp2(haha a,haha b)

{

    return a.no<b.no;

}

int main()

{

    int n,k,l,a,b,i,j,m,cnt;

    cin>>n>>k>>l;

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

    {

        bcj1[i]=bcj2[i]=i;

        pp[i].ans=0;pp[i].no=i;

    }

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

    {

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

        join1(a,b);

    }

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

    {

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

        join2(a,b);

    }

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

    {

        bcj1[i]=father1(bcj1[i]);

        pp[i].p=bcj1[i];

        bcj2[i]=father2(bcj2[i]);

        pp[i].q=bcj2[i];

    }

    sort(pp+1,pp+1+n,cmp1);cnt=0;

    pp[0].p=pp[0].q=0;j=1;

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

    {

        if (i<=n && pp[i].p==pp[i-1].p && pp[i].q==pp[i-1].q) continue;

        for(m=j;m<=i-1;m++)

            pp[m].ans=i-j;

        j=i;

    }

    sort(pp+1,pp+1+n,cmp2);

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

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

    cout<<endl;

    return 0;

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

#include <bits/stdc++.h>



using namespace std;



int fa[200005];

int fa1[200005];

int vis[200005];



int find1(int a)

{

    if(fa[a]!=a)

        fa[a]=find1(fa[a]);

    return fa[a];

}

void union1(int a,int b)

{

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

}



int find2(int a)

{

    if(fa1[a]!=a)

        fa1[a]=find2(fa1[a]);

    return fa1[a];

}

void union2(int a,int b)

{

    fa1[find2(a)]=find2(b);

}

map<long long,int> mp;

int main()

{

    int n,k,l;

    cin>>n>>k>>l;

    memset(vis,0,sizeof(vis));

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

    {

        fa[i]=i;

        fa1[i]=i;

    }

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

    {

        int l1,r;

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

        union1(l1,r);

    }

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

    {

        int l1,r;

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

        //if(find1(l1)==find1(r))

        union2(l1,r);

        //cout<<find1(l1)<<' '<<find1(r);

    }

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

    {

        if(mp.find((long long)((long long)find1(i)*200005+(long long)find2(i)))==mp.end())

            mp[(long long)((long long)find1(i)*200005+(long long)find2(i))]=0;

        mp[(long long)((long long)find1(i)*200005+(long long)find2(i))]++;

    }

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

        printf("%d ",mp[(long long)((long long)find1(i)*200005+(long long)find2(i))]);

    printf("%d\n",mp[(long long)((long long)find1(n)*200005+(long long)find2(n))]);

    return 0;

}


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

using namespace std;

int bcj1[200010],bcj2[200010];

int father1(int k)

{

    return bcj1[k]==k?k:bcj1[k]=father1(bcj1[k]);

}

void join1(int x,int y)

{

    int fa,fb;

    fa=father1(x);fb=father1(y);

    bcj1[fb]=fa;

}

int father2(int k)

{

    return bcj2[k]==k?k:bcj2[k]=father2(bcj2[k]);

}

void join2(int x,int y)

{

    int fa,fb;

    fa=father2(x);fb=father2(y);

    bcj2[fb]=fa;

}

struct haha

{

    int p,q,no,ans;

}pp[200010];

bool cmp1(haha a,haha b)

{

    if (a.p==b.p) return a.q<b.q;

    return a.p<b.p;

}

bool cmp2(haha a,haha b)

{

    return a.no<b.no;

}

int main()

{

    int n,k,l,a,b,i,j,m,cnt;

    cin>>n>>k>>l;

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

    {

        bcj1[i]=bcj2[i]=i;

        pp[i].ans=0;pp[i].no=i;

    }

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

    {

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

        join1(a,b);

    }

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

    {

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

        join2(a,b);

    }

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

    {

        bcj1[i]=father1(bcj1[i]);

        pp[i].p=bcj1[i];

        bcj2[i]=father2(bcj2[i]);

        pp[i].q=bcj2[i];

    }

    sort(pp+1,pp+1+n,cmp1);cnt=0;

    pp[0].p=pp[0].q=0;j=1;

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

    {

        if (i<=n && pp[i].p==pp[i-1].p && pp[i].q==pp[i-1].q) continue;

        for(m=j;m<=i-1;m++)

            pp[m].ans=i-j;

        j=i;

    }

    sort(pp+1,pp+1+n,cmp2);

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

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

    cout<<endl;

    return 0;

}
// 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: 6.339598844101668x):
#include<bits/stdc++.h>

using namespace std;

int bcj1[200010],bcj2[200010];

int father1(int k)

{

    return bcj1[k]==k?k:bcj1[k]=father1(bcj1[k]);

}

void join1(int x,int y)

{

    int fa,fb;

    fa=father1(x);fb=father1(y);

    bcj1[fb]=fa;

}

int father2(int k)

{

    return bcj2[k]==k?k:bcj2[k]=father2(bcj2[k]);

}

void join2(int x,int y)

{

    int fa,fb;

    fa=father2(x);fb=father2(y);

    bcj2[fb]=fa;

}

struct haha

{

    int p,q,no,ans;

}pp[200010];

bool cmp1(haha a,haha b)

{

    if (a.p==b.p) return a.q<b.q;

    return a.p<b.p;

}

bool cmp2(haha a,haha b)

{

    return a.no<b.no;

}

int main()

{

    int n,k,l,a,b,i,j,m,cnt;

    cin>>n>>k>>l;

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

    {

        bcj1[i]=bcj2[i]=i;

        pp[i].ans=0;pp[i].no=i;

    }

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

    {

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

        join1(a,b);

    }

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

    {

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

        join2(a,b);

    }

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

    {

        bcj1[i]=father1(bcj1[i]);

        pp[i].p=bcj1[i];

        bcj2[i]=father2(bcj2[i]);

        pp[i].q=bcj2[i];

    }

    sort(pp+1,pp+1+n,cmp1);cnt=0;

    pp[0].p=pp[0].q=0;j=1;

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

    {

        if (i<=n && pp[i].p==pp[i-1].p && pp[i].q==pp[i-1].q) continue;

        for(m=j;m<=i-1;m++)

            pp[m].ans=i-j;

        j=i;

    }

    sort(pp+1,pp+1+n,cmp2);

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

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

    cout<<endl;

    return 0;

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

using namespace std;



const int N = 2e5+10;

int fa1[N],fa2[N];

int findroot1(int u)

{

    return fa1[u]==u?u:fa1[u]=findroot1(fa1[u]);

}

int findroot2(int u)

{

    return fa2[u]==u?u:fa2[u]=findroot2(fa2[u]);

}

set<int>s2[N];

int ans[N];

int main()

{

    int n,k,l;

    int u,v;

    // freopen("in.txt","r",stdin);

    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++)

    {

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

        int uu=findroot1(u);

        int vv=findroot1(v);

        if(uu==vv) continue;

        else fa1[vv]=uu;

    }

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

    {

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

        int uu=findroot2(u);

        int vv=findroot2(v);

        if(uu==vv) continue;

        else fa2[vv]=uu;

    }

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

    {

        v=findroot2(i);

        s2[v].insert(i);

    }

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

    {

        if(!s2[i].empty())

        {

            map<int,int>mp;

            for(auto it:s2[i])

            {

                int uu=findroot1(it);

                mp[uu]++;

            }

            for(auto it:s2[i])

            {

                int uu=findroot1(it);

                ans[it]=mp[uu];

            }

        }

    }

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

    {

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

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

        else printf("\n");

    }

    return 0;

}


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

using namespace std;

int bcj1[200010],bcj2[200010];

int father1(int k)

{

    return bcj1[k]==k?k:bcj1[k]=father1(bcj1[k]);

}

void join1(int x,int y)

{

    int fa,fb;

    fa=father1(x);fb=father1(y);

    bcj1[fb]=fa;

}

int father2(int k)

{

    return bcj2[k]==k?k:bcj2[k]=father2(bcj2[k]);

}

void join2(int x,int y)

{

    int fa,fb;

    fa=father2(x);fb=father2(y);

    bcj2[fb]=fa;

}

struct haha

{

    int p,q,no,ans;

}pp[200010];

bool cmp1(haha a,haha b)

{

    if (a.p==b.p) return a.q<b.q;

    return a.p<b.p;

}

bool cmp2(haha a,haha b)

{

    return a.no<b.no;

}

int main()

{

    int n,k,l,a,b,i,j,m,cnt;

    cin>>n>>k>>l;

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

    {

        bcj1[i]=bcj2[i]=i;

        pp[i].ans=0;pp[i].no=i;

    }

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

    {

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

        join1(a,b);

    }

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

    {

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

        join2(a,b);

    }

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

    {

        bcj1[i]=father1(bcj1[i]);

        pp[i].p=bcj1[i];

        bcj2[i]=father2(bcj2[i]);

        pp[i].q=bcj2[i];

    }

    sort(pp+1,pp+1+n,cmp1);cnt=0;

    pp[0].p=pp[0].q=0;j=1;

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

    {

        if (i<=n && pp[i].p==pp[i-1].p && pp[i].q==pp[i-1].q) continue;

        for(m=j;m<=i-1;m++)

            pp[m].ans=i-j;

        j=i;

    }

    sort(pp+1,pp+1+n,cmp2);

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

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

    cout<<endl;

    return 0;

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

#include <algorithm>

#include <map>

#include <iostream>

using namespace std;

#define x first

#define y second

#define mp make_pair

#define REP(i,j,k)  for(int i = (j); i <= (k); ++i)

#define REPD(i,j,k) for(int i = (j); i >= (k); --i)

#define IOS ios::sync_with_stdio(0);cin.tie(0);





const int maxn = 3e5;



int f[maxn];

int find(int x){ return f[x]==x?x:f[x]=find(f[x]); }



void go(int n,int m,int a[])

{

	REP(i,1,n)

		f[i]=i;

	while(m--)

	{

		int x,y;

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

		if(find(x)!=find(y))

			f[find(x)]=find(y);

	}

	REP(i,1,n)

		a[i]=find(i);

}

int a[maxn],b[maxn];

map<pair<int,int>,int> tot;

int init()

{

	int n,m,p;

	if(scanf("%d%d%d",&n,&m,&p)==EOF) return 0;

	go(n,m,a);

	go(n,p,b);

	tot.clear();

	REP(i,1,n)

		if(tot.count(mp(a[i],b[i]))==0)

			tot[mp(a[i],b[i])]=1;

		else ++tot[mp(a[i],b[i])];

	REP(i,1,n)

		if(i==n)

			printf("%d\n",tot[mp(a[i],b[i])]);

		else printf("%d ",tot[mp(a[i],b[i])]);

	return 1;

}



void solve()

{

}



int main()

{

	IOS

	

	while(init())

	solve();

	

	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: 4.191918690148557x):
#include <cstdio>

#include <algorithm>

#include <map>

#include <iostream>

using namespace std;

#define x first

#define y second

#define mp make_pair

#define REP(i,j,k)  for(int i = (j); i <= (k); ++i)

#define REPD(i,j,k) for(int i = (j); i >= (k); --i)

#define IOS ios::sync_with_stdio(0);cin.tie(0);





const int maxn = 3e5;



int f[maxn];

int find(int x){ return f[x]==x?x:f[x]=find(f[x]); }



void go(int n,int m,int a[])

{

	REP(i,1,n)

		f[i]=i;

	while(m--)

	{

		int x,y;

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

		if(find(x)!=find(y))

			f[find(x)]=find(y);

	}

	REP(i,1,n)

		a[i]=find(i);

}

int a[maxn],b[maxn];

map<pair<int,int>,int> tot;

int init()

{

	int n,m,p;

	if(scanf("%d%d%d",&n,&m,&p)==EOF) return 0;

	go(n,m,a);

	go(n,p,b);

	tot.clear();

	REP(i,1,n)

		if(tot.count(mp(a[i],b[i]))==0)

			tot[mp(a[i],b[i])]=1;

		else ++tot[mp(a[i],b[i])];

	REP(i,1,n)

		if(i==n)

			printf("%d\n",tot[mp(a[i],b[i])]);

		else printf("%d ",tot[mp(a[i],b[i])]);

	return 1;

}



void solve()

{

}



int main()

{

	IOS

	

	while(init())

	solve();

	

	return 0;

}