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

#include <iostream>

#include <iomanip>

#include <cstring>

#include <string>

#include <vector>

#include <queue>

#include <cmath>

using namespace std;



const int MAXN = 200000 + 10;

const int MAXL = 100000 + 10;



struct DSU

{

    int fa[MAXN];



    int find(int x)

    {

        if(x == fa[x])

            return x;

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

    }



    void merge(int x, int y)

    {

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

    }

}d1, d2;



int tmp[MAXN], ans[MAXN], cnt[MAXN];



void init(DSU & d)

{

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

        d.fa[i] = i;

}



int N, K, L;

int main()

{

    init(d1);

    init(d2);

    int u, v;

    cin >> N >> K >> L ;



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

        cin >> u >> v, d1.merge(u, v);

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

        cin >> u >> v, d2.merge(u, v);



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

        d1.fa[i] = d1.find(i),

        d2.fa[i] = d2.find(i);

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

        tmp[i] = i;

    sort(tmp+1, tmp+N+1, [](int x, int y)-> bool {return d1.fa[x] < d1.fa[y];});





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

    {

        int j = i;

        while(j < N && d1.fa[tmp[j]] == d1.fa[tmp[j+1]])

            j++;



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

            cnt[d2.fa[tmp[t]]]++;

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

            ans[tmp[t]] = cnt[d2.fa[tmp[t]]];

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

            cnt[d2.fa[tmp[t]]]--;

        i = j ;

    }



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

        cout << ans[i] << " " ;



    return 0;

}


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

using namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

const int N=2e5+10;

const int maxn=1e6;

int fa1[N],fa2[N];

int find1(int x)

{

    if(fa1[x]!=x) fa1[x]=find1(fa1[x]);

    return fa1[x];

}

int find2(int x)

{

    if(fa2[x]!=x) fa2[x]=find2(fa2[x]);

    return fa2[x];

}

int main()

{

    ios::sync_with_stdio(0);

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

    int n,k,l,x,y;

    cin>>n>>k>>l;

    for(int i=1;i<=n;i++) fa1[i]=i,fa2[i]=i;

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

    {

        cin>>x>>y;

        int r1=find1(x);

        int r2=find1(y);

        if(r1!=r2) fa1[r2]=r1;

    }

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

    {

        cin>>x>>y;

        int r1=find2(x);

        int r2=find2(y);

        if(r1!=r2) fa2[r2]=r1;

    }

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

    {

        find1(i);

        find2(i);

    }

    map<pair<int,int>,int>f;

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

    {

        f[make_pair(fa1[i],fa2[i])]++;

    }

    for(int i=1;i<=n;i++) cout<<f[make_pair(fa1[i],fa2[i])]<<" ";

    return 0;

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

using namespace std;



long long f(long long a[],long long x)

{

    if(x==a[x]);

    else a[x]=f(a,a[x]);

    return a[x];

}

long long a[200010];

long long b[200010];

long long c[200010];

long long d[200010];

int e[200010];

int main()

{



    long long n,m,k;

    long long x,y,i;

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

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

    {

        a[i]=i;

        b[i]=i;

    }

    while(m--)

    {

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

        x=f(a,x);

        y=f(a,y);

        a[x]=y;

    }

    while(k--)

    {

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

        x=f(b,x);

        y=f(b,y);

        b[x]=y;

    }

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

    {

        c[i]=f(a,i)+(n+1)*f(b,i);

        d[i]=c[i];

    }

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

    memset(e,0,sizeof(e));

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

    {

        y=lower_bound(d+1,d+n+1,c[i])-d;

        e[y]++;

    }

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

    {

        y=lower_bound(d+1,d+n+1,c[i])-d;

        if(i==n)printf("%d\n",e[y]);

        else printf("%d ",e[y]);

    }

    return 0;

}


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

#include<ctime>

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

#define mp make_pair

using namespace std;



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



struct dsu

{

    int fa[200010],rank[200010];

    

    void init(int n)

    {

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

        {

            fa[i]=i;

        }

    }

    

    int find(int x)

    {

        if(fa[x]==x)

        {

            return x;

        }

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

    }

    

    void union_(int x,int y)

    {

        int fx=find(x);

        int fy=find(y);

        if(fx==fy)

        {

            return ;

        }

        if(rank[fx]<rank[fy])

        {

            fa[fx]=fy;

        }

        else

        {

            fa[fy]=fx;

            if(rank[fx]==rank[fy])

            {

                rank[x]++;

            }

        }

    }

    

    int same(int x,int y)

    {

        return find(x)==find(y);

    }

}a,b;



int main()

{

    //give the fucking vjudge a flying fucking

    int n,x,y;

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

    a.init(n);

    b.init(n);

    int from,to;

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

    {

        scanf("%d%d",&from,&to);

        a.union_(from,to);

    }

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

    {

        scanf("%d%d",&from,&to);

        b.union_(from,to);

    }

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

    {

        m[mp(a.find(i),b.find(i))]++;

    }

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

    {

        printf("%d ",m[mp(a.find(i),b.find(i))]);

    }

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

using namespace std;

#define INF 0x3f3f3f3f

#define maxn 212345

#define met(a, b) memset(a, b, sizeof(a))

class UMS

{

public:

    int f[maxn];

    UMS()

    {

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

        {

            f[i] = i;

        }

    }

    int getf(int u)

    {

        if(u == f[u])

            return f[u];

        else

        {

            f[u] = getf(f[u]);

            return f[u];

        }

    }

    void Merge(int u, int v)

    {

        int f1 = getf(u);

        int f2 = getf(v);

        if(f1 != f2)

        {

            f[f1] = f2;

        }

    }

};

vector<int> vec[maxn];

map<int, int> q;

int main()

{

    UMS u1, u2;

    int n, k, l, u, v;

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

    while(k--)

    {

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

        u1.Merge(u, v);

    }

    while(l--)

    {

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

        u2.Merge(u, v);

    }

    int vis[maxn];

    met(vis, 0);

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

    {

        int fa = u1.getf(i);

        vec[fa].push_back(i);

    }

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

    {

        q.clear();

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

        {

            q[u2.getf(vec[i][j])] ++;

        }

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

        {

            vis[vec[i][j]] += q[u2.getf(vec[i][j])];

        }



    }

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

    {

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

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

        else printf(" ");

    }

    return 0;

}


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

#include<ctime>

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

#define mp make_pair

using namespace std;



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



struct dsu

{

    int fa[200010],rank[200010];

    

    void init(int n)

    {

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

        {

            fa[i]=i;

        }

    }

    

    int find(int x)

    {

        if(fa[x]==x)

        {

            return x;

        }

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

    }

    

    void union_(int x,int y)

    {

        int fx=find(x);

        int fy=find(y);

        if(fx==fy)

        {

            return ;

        }

        if(rank[fx]<rank[fy])

        {

            fa[fx]=fy;

        }

        else

        {

            fa[fy]=fx;

            if(rank[fx]==rank[fy])

            {

                rank[x]++;

            }

        }

    }

    

    int same(int x,int y)

    {

        return find(x)==find(y);

    }

}a,b;



int main()

{

    //give the fucking vjudge a flying fucking

    int n,x,y;

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

    a.init(n);

    b.init(n);

    int from,to;

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

    {

        scanf("%d%d",&from,&to);

        a.union_(from,to);

    }

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

    {

        scanf("%d%d",&from,&to);

        b.union_(from,to);

    }

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

    {

        m[mp(a.find(i),b.find(i))]++;

    }

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

    {

        printf("%d ",m[mp(a.find(i),b.find(i))]);

    }

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

using namespace std;



long long f(long long a[],long long x)

{

    if(x==a[x]);

    else a[x]=f(a,a[x]);

    return a[x];

}

long long a[200010];

long long b[200010];

long long c[200010];

long long d[200010];

int e[200010];

int main()

{



    long long n,m,k;

    long long x,y,i;

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

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

    {

        a[i]=i;

        b[i]=i;

    }

    while(m--)

    {

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

        x=f(a,x);

        y=f(a,y);

        a[x]=y;

    }

    while(k--)

    {

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

        x=f(b,x);

        y=f(b,y);

        b[x]=y;

    }

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

    {

        c[i]=f(a,i)+(n+1)*f(b,i);

        d[i]=c[i];

    }

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

    memset(e,0,sizeof(e));

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

    {

        y=lower_bound(d+1,d+n+1,c[i])-d;

        e[y]++;

    }

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

    {

        y=lower_bound(d+1,d+n+1,c[i])-d;

        if(i==n)printf("%d\n",e[y]);

        else printf("%d ",e[y]);

    }

    return 0;

}


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

#define x first

#define y second

#define pii pair<int,int>

#define ll long long

#define pll pair<ll,ll>

#define pbb pair<bool,bool>

#define mp make_pair

#define pb push_back

#define pf push_front

#define popb pop_back

#define popf pop_front

#define xmod (ll)(1e9+7) 

#define hmod 1286031825167LL

using namespace std;



int n,k,l,dsu_road[200005],dsu_rail[200005],u,v;

map <pii,int> m;

int find_road(int x){

	if (dsu_road[x] == x)

	return x;

	return dsu_road[x]=find_road(dsu_road[x]);

}

int find_rail(int x){

	if (dsu_rail[x] == x)

	return x;

	return dsu_rail[x]=find_rail(dsu_rail[x]);

}

int main(){	

    ios::sync_with_stdio(false);

    cin >> n >> k >> l;

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

    	dsu_road[i]=i;

    	dsu_rail[i]=i;

	}

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

		cin >> u >> v;

		dsu_road[find_road(u)]=find_road(v);

	}

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

		cin >> u >> v;

		dsu_rail[find_rail(u)]=find_rail(v);

	}

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

		m[mp(find_road(i),find_rail(i))]++;

	}

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

		cout << m[mp(find_road(i),find_rail(i))] << " ";

	}

	cout << "\n";

    return 0;

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

using namespace std;

#define INF 0x3f3f3f3f

#define maxn 212345

#define met(a, b) memset(a, b, sizeof(a))

class UMS

{

public:

    int f[maxn];

    UMS()

    {

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

        {

            f[i] = i;

        }

    }

    int getf(int u)

    {

        if(u == f[u])

            return f[u];

        else

        {

            f[u] = getf(f[u]);

            return f[u];

        }

    }

    void Merge(int u, int v)

    {

        int f1 = getf(u);

        int f2 = getf(v);

        if(f1 != f2)

        {

            f[f1] = f2;

        }

    }

};

vector<int> vec[maxn];

map<int, int> q;

int main()

{

    UMS u1, u2;

    int n, k, l, u, v;

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

    while(k--)

    {

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

        u1.Merge(u, v);

    }

    while(l--)

    {

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

        u2.Merge(u, v);

    }

    int vis[maxn];

    met(vis, 0);

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

    {

        int fa = u1.getf(i);

        vec[fa].push_back(i);

    }

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

    {

        q.clear();

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

        {

            q[u2.getf(vec[i][j])] ++;

        }

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

        {

            vis[vec[i][j]] += q[u2.getf(vec[i][j])];

        }



    }

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

    {

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

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

        else printf(" ");

    }

    return 0;

}


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

#define x first

#define y second

#define pii pair<int,int>

#define ll long long

#define pll pair<ll,ll>

#define pbb pair<bool,bool>

#define mp make_pair

#define pb push_back

#define pf push_front

#define popb pop_back

#define popf pop_front

#define xmod (ll)(1e9+7) 

#define hmod 1286031825167LL

using namespace std;



int n,k,l,dsu_road[200005],dsu_rail[200005],u,v;

map <pii,int> m;

int find_road(int x){

	if (dsu_road[x] == x)

	return x;

	return dsu_road[x]=find_road(dsu_road[x]);

}

int find_rail(int x){

	if (dsu_rail[x] == x)

	return x;

	return dsu_rail[x]=find_rail(dsu_rail[x]);

}

int main(){	

    ios::sync_with_stdio(false);

    cin >> n >> k >> l;

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

    	dsu_road[i]=i;

    	dsu_rail[i]=i;

	}

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

		cin >> u >> v;

		dsu_road[find_road(u)]=find_road(v);

	}

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

		cin >> u >> v;

		dsu_rail[find_rail(u)]=find_rail(v);

	}

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

		m[mp(find_road(i),find_rail(i))]++;

	}

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

		cout << m[mp(find_road(i),find_rail(i))] << " ";

	}

	cout << "\n";

    return 0;

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

#include <iostream>

#include <iomanip>

#include <cstring>

#include <string>

#include <vector>

#include <queue>

#include <cmath>

using namespace std;



const int MAXN = 200000 + 10;

const int MAXL = 100000 + 10;



struct DSU

{

    int fa[MAXN];



    int find(int x)

    {

        if(x == fa[x])

            return x;

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

    }



    void merge(int x, int y)

    {

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

    }

}d1, d2;



int tmp[MAXN], ans[MAXN], cnt[MAXN];



void init(DSU & d)

{

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

        d.fa[i] = i;

}



int N, K, L;

int main()

{

    init(d1);

    init(d2);

    int u, v;

    cin >> N >> K >> L ;



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

        cin >> u >> v, d1.merge(u, v);

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

        cin >> u >> v, d2.merge(u, v);



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

        d1.fa[i] = d1.find(i),

        d2.fa[i] = d2.find(i);

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

        tmp[i] = i;

    sort(tmp+1, tmp+N+1, [](int x, int y)-> bool {return d1.fa[x] < d1.fa[y];});





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

    {

        int j = i;

        while(j < N && d1.fa[tmp[j]] == d1.fa[tmp[j+1]])

            j++;



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

            cnt[d2.fa[tmp[t]]]++;

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

            ans[tmp[t]] = cnt[d2.fa[tmp[t]]];

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

            cnt[d2.fa[tmp[t]]]--;

        i = j ;

    }



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

        cout << ans[i] << " " ;



    return 0;

}


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

#define x first

#define y second

#define pii pair<int,int>

#define ll long long

#define pll pair<ll,ll>

#define pbb pair<bool,bool>

#define mp make_pair

#define pb push_back

#define pf push_front

#define popb pop_back

#define popf pop_front

#define xmod (ll)(1e9+7) 

#define hmod 1286031825167LL

using namespace std;



int n,k,l,dsu_road[200005],dsu_rail[200005],u,v;

map <pii,int> m;

int find_road(int x){

	if (dsu_road[x] == x)

	return x;

	return dsu_road[x]=find_road(dsu_road[x]);

}

int find_rail(int x){

	if (dsu_rail[x] == x)

	return x;

	return dsu_rail[x]=find_rail(dsu_rail[x]);

}

int main(){	

    ios::sync_with_stdio(false);

    cin >> n >> k >> l;

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

    	dsu_road[i]=i;

    	dsu_rail[i]=i;

	}

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

		cin >> u >> v;

		dsu_road[find_road(u)]=find_road(v);

	}

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

		cin >> u >> v;

		dsu_rail[find_rail(u)]=find_rail(v);

	}

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

		m[mp(find_road(i),find_rail(i))]++;

	}

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

		cout << m[mp(find_road(i),find_rail(i))] << " ";

	}

	cout << "\n";

    return 0;

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

using namespace std;



long long f(long long a[],long long x)

{

    if(x==a[x]);

    else a[x]=f(a,a[x]);

    return a[x];

}

long long a[200010];

long long b[200010];

long long c[200010];

long long d[200010];

int e[200010];

int main()

{



    long long n,m,k;

    long long x,y,i;

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

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

    {

        a[i]=i;

        b[i]=i;

    }

    while(m--)

    {

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

        x=f(a,x);

        y=f(a,y);

        a[x]=y;

    }

    while(k--)

    {

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

        x=f(b,x);

        y=f(b,y);

        b[x]=y;

    }

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

    {

        c[i]=f(a,i)+(n+1)*f(b,i);

        d[i]=c[i];

    }

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

    memset(e,0,sizeof(e));

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

    {

        y=lower_bound(d+1,d+n+1,c[i])-d;

        e[y]++;

    }

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

    {

        y=lower_bound(d+1,d+n+1,c[i])-d;

        if(i==n)printf("%d\n",e[y]);

        else printf("%d ",e[y]);

    }

    return 0;

}


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

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

const int mod=7+1e9;

ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

ll lcm(ll x,ll y){return x/gcd(x,y)*y;}

ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}

ll getInv(ll x,ll p){return qpow(x,p-2,p);}

const int N=5+2e5;

int fa1[N],fa2[N];

int find(int x,int* fa){ return fa[x]!=x?fa[x]=find(fa[x],fa):x;}

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

    x=find(x,fa),y=find(y,fa);

    if(x!=y) fa[x]=y;

}

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

int main(){

    int n,k,l; cin>>n>>k>>l;

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

    while(k--){

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

        merge(u,v,fa1);

    }

    while(l--){

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

        merge(u,v,fa2);

    }

    for(int i=1;i<=n;i++) fa1[i]=find(i,fa1),fa2[i]=find(i,fa2);

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

    //for(auto v:cnt) printf("{%d,%d}:%d\n",v.first.first,v.first.second,v.second);

    for(int i=1;i<=n;i++) cout<<cnt[{fa1[i],fa2[i]}]<<' ';

    puts("");

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

using namespace std;

#define INF 0x3f3f3f3f

#define maxn 212345

#define met(a, b) memset(a, b, sizeof(a))

class UMS

{

public:

    int f[maxn];

    UMS()

    {

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

        {

            f[i] = i;

        }

    }

    int getf(int u)

    {

        if(u == f[u])

            return f[u];

        else

        {

            f[u] = getf(f[u]);

            return f[u];

        }

    }

    void Merge(int u, int v)

    {

        int f1 = getf(u);

        int f2 = getf(v);

        if(f1 != f2)

        {

            f[f1] = f2;

        }

    }

};

vector<int> vec[maxn];

map<int, int> q;

int main()

{

    UMS u1, u2;

    int n, k, l, u, v;

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

    while(k--)

    {

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

        u1.Merge(u, v);

    }

    while(l--)

    {

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

        u2.Merge(u, v);

    }

    int vis[maxn];

    met(vis, 0);

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

    {

        int fa = u1.getf(i);

        vec[fa].push_back(i);

    }

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

    {

        q.clear();

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

        {

            q[u2.getf(vec[i][j])] ++;

        }

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

        {

            vis[vec[i][j]] += q[u2.getf(vec[i][j])];

        }



    }

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

    {

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

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

        else printf(" ");

    }

    return 0;

}


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

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

const int mod=7+1e9;

ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

ll lcm(ll x,ll y){return x/gcd(x,y)*y;}

ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}

ll getInv(ll x,ll p){return qpow(x,p-2,p);}

const int N=5+2e5;

int fa1[N],fa2[N];

int find(int x,int* fa){ return fa[x]!=x?fa[x]=find(fa[x],fa):x;}

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

    x=find(x,fa),y=find(y,fa);

    if(x!=y) fa[x]=y;

}

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

int main(){

    int n,k,l; cin>>n>>k>>l;

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

    while(k--){

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

        merge(u,v,fa1);

    }

    while(l--){

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

        merge(u,v,fa2);

    }

    for(int i=1;i<=n;i++) fa1[i]=find(i,fa1),fa2[i]=find(i,fa2);

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

    //for(auto v:cnt) printf("{%d,%d}:%d\n",v.first.first,v.first.second,v.second);

    for(int i=1;i<=n;i++) cout<<cnt[{fa1[i],fa2[i]}]<<' ';

    puts("");

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

#include <iostream>

#include <iomanip>

#include <cstring>

#include <string>

#include <vector>

#include <queue>

#include <cmath>

using namespace std;



const int MAXN = 200000 + 10;

const int MAXL = 100000 + 10;



struct DSU

{

    int fa[MAXN];



    int find(int x)

    {

        if(x == fa[x])

            return x;

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

    }



    void merge(int x, int y)

    {

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

    }

}d1, d2;



int tmp[MAXN], ans[MAXN], cnt[MAXN];



void init(DSU & d)

{

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

        d.fa[i] = i;

}



int N, K, L;

int main()

{

    init(d1);

    init(d2);

    int u, v;

    cin >> N >> K >> L ;



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

        cin >> u >> v, d1.merge(u, v);

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

        cin >> u >> v, d2.merge(u, v);



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

        d1.fa[i] = d1.find(i),

        d2.fa[i] = d2.find(i);

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

        tmp[i] = i;

    sort(tmp+1, tmp+N+1, [](int x, int y)-> bool {return d1.fa[x] < d1.fa[y];});





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

    {

        int j = i;

        while(j < N && d1.fa[tmp[j]] == d1.fa[tmp[j+1]])

            j++;



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

            cnt[d2.fa[tmp[t]]]++;

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

            ans[tmp[t]] = cnt[d2.fa[tmp[t]]];

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

            cnt[d2.fa[tmp[t]]]--;

        i = j ;

    }



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

        cout << ans[i] << " " ;



    return 0;

}


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

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

const int mod=7+1e9;

ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

ll lcm(ll x,ll y){return x/gcd(x,y)*y;}

ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}

ll getInv(ll x,ll p){return qpow(x,p-2,p);}

const int N=5+2e5;

int fa1[N],fa2[N];

int find(int x,int* fa){ return fa[x]!=x?fa[x]=find(fa[x],fa):x;}

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

    x=find(x,fa),y=find(y,fa);

    if(x!=y) fa[x]=y;

}

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

int main(){

    int n,k,l; cin>>n>>k>>l;

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

    while(k--){

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

        merge(u,v,fa1);

    }

    while(l--){

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

        merge(u,v,fa2);

    }

    for(int i=1;i<=n;i++) fa1[i]=find(i,fa1),fa2[i]=find(i,fa2);

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

    //for(auto v:cnt) printf("{%d,%d}:%d\n",v.first.first,v.first.second,v.second);

    for(int i=1;i<=n;i++) cout<<cnt[{fa1[i],fa2[i]}]<<' ';

    puts("");

}