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

#include <cmath>

#include <queue>

#include <stack>

#include <vector>

#include <cstdio>

#include <string>

#include <cstring>

#include <sstream>

#include <algorithm>



using namespace std;



int ro[200005], ra[200005], n, k, l;



int Find(int *r, int x) {

    return r[x]==x ? x : r[x]=Find(r, r[x]);

}



void init() {

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

        ra[i]=ro[i]=i;

    }

}



vector <int> ve[200005];

map <int, int> ma;

int ans[200005];



int main () {

    int u, v;

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

    init();

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

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

        u=Find(ro, u), v=Find(ro, v);

        if(u!=v) {

            ro[u]=v;

        }

    }



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

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

        u=Find(ra, u), v=Find(ra, v);

        if(u!=v) {

            ra[u]=v;

        }

    }



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

        ve[Find(ro, i)].push_back(i);

    }



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

        ma.clear();

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

            ma[Find(ra, ve[i][j])]++;

        }



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

            ans[ve[i][j]]+=ma[Find(ra, ve[i][j])];

        }

    }



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

        printf("%d%c", ans[i], i==n ? '\n' : ' ');

    }

    return 0;

}

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

using namespace std;

const int N=200000+10;

const int INF=10000000;

int p1[N],p2[N];

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

int find(int x,int *p)

{

    return p[x]==x?p[x]:p[x]=find(p[x],p);

}

void cha(int x,int y,int *p)

{

    int px=find(x,p);

    int py=find(y,p);

    if(px!=py)

    {

        p[px]=py;

    }

}

int main()

{

    int n,k,l;

    cin>>n>>k>>l;

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

        p1[i]=i,p2[i]=i;

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

    {

        int x,y;

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

        cha(x,y,p1);

    }

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

    {

        int x,y;

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

        cha(x,y,p2);

    }

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

    {

        find(i,p1);

        find(i,p2);

    }

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

        m[make_pair(p1[i],p2[i])]++;

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

        printf("%d ",m[make_pair(p1[i],p2[i])]);

    putchar('\n');

    return 0;

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

#include<cstring>

#include<algorithm>

#include<set>

#include<map>

#define MAXN 200000

using namespace std;

typedef pair<int,int> PII;

map<PII,int> mp;

int setfa[2][MAXN+5];

void Init()

{

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

		setfa[0][i]=setfa[1][i]=i;

}

int Findfa(int x,int typ)

{

	if(setfa[typ][x]==x)

		return x;

	return setfa[typ][x]=Findfa(setfa[typ][x],typ);

}

void Union(int x,int y,int typ)

{

	int fx=Findfa(x,typ),fy=Findfa(y,typ);

	if(fx==fy)

		return;

	setfa[typ][fx]=fy;

}

int main()

{

	Init();

	int N,K,L;

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

	int x,y;

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

	{

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

		Union(x,y,0);

	}

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

	{

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

		Union(x,y,1);

	}

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

	{

		int a=Findfa(i,0),b=Findfa(i,1);

		mp[PII(a,b)]++;

	}

	int Ans;

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

	{

		int a=Findfa(i,0),b=Findfa(i,1);

		Ans=mp[PII(a,b)];

		if(i==1)

			printf("%d",Ans);

		else

			printf(" %d",Ans);

	}

	printf("\n");

	return 0;

}

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

using namespace std;

const int N=200000+10;

const int INF=10000000;

int p1[N],p2[N];

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

int find(int x,int *p)

{

    return p[x]==x?p[x]:p[x]=find(p[x],p);

}

void cha(int x,int y,int *p)

{

    int px=find(x,p);

    int py=find(y,p);

    if(px!=py)

    {

        p[px]=py;

    }

}

int main()

{

    int n,k,l;

    cin>>n>>k>>l;

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

        p1[i]=i,p2[i]=i;

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

    {

        int x,y;

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

        cha(x,y,p1);

    }

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

    {

        int x,y;

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

        cha(x,y,p2);

    }

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

    {

        find(i,p1);

        find(i,p2);

    }

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

        m[make_pair(p1[i],p2[i])]++;

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

        printf("%d ",m[make_pair(p1[i],p2[i])]);

    putchar('\n');

    return 0;

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

#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

#include <vector>

#include <map>

#define ms(x) memset(x, 0, sizeof(x))

#define inf 0x3f3f3f3f

using namespace std;

const int N = 200005;

vector<int >book[N];

int faf[N], fag[N];

int vis[N];

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

void init() {

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

        faf[i] = fag[i] = i;

    }

}

int Find(int *f, int x){

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

    else{

        f[x] = Find(f, f[x]);

        return f[x];

    }

}

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

    int a = Find(f, x) , b = Find(f, y);

    if(a!=b){

        f[b] = a;

    }

}

int main() {

    int n, k, l;

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

        int u, v;

        init();

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

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

            Merge(faf, u, v);

        }

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

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

            Merge(fag, u, v);

        }

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

            ++mp[{Find(faf, i), Find(fag, i)}];        //将同一个连通块中的点 集合起来

        }

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

            printf("%d%c", mp[{Find(faf, i), Find(fag, i)}],i==n?'\n':' ');

        }

    }

    return 0;

}


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

 

using namespace std;

 

typedef long long ll;

 

const int MAXN = 2e5+7;

const int Inf = 0x3f3f3f3f;

 

int pre1[MAXN],pre2[MAXN];

 

int finds(int x,int *pre)

{

    return pre[x] == x? pre[x]:pre[x] = finds(pre[x],pre);

}

 

void join(int x,int y,int *pre)

{

    int px = finds(x,pre);

    int py = finds(y,pre);

    if( px!=py)

    {

        pre[px] = py;

    }

}

int main()

{

    int n,k,l;

    cin>>n>>k>>l;

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

        pre1[i] = i,pre2[i] = i;

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

    {

        int x,y;

        cin>>x>>y;

        join(x,y,pre1);

    }

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

    {

        int x,y;

        cin>>x>>y;

        join(x,y,pre2);

    }

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

    {

        finds(i,pre1);

        finds(i,pre2);

    }

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

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

    {

        mp[make_pair(pre1[i],pre2[i])] ++;

    }

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

    {

        cout<<mp[make_pair(pre1[i],pre2[i])]<<" ";

    }

    cout<<endl;

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

#include <cmath>

#include <queue>

#include <stack>

#include <vector>

#include <cstdio>

#include <string>

#include <cstring>

#include <sstream>

#include <algorithm>



using namespace std;



int ro[200005], ra[200005], n, k, l;



int Find(int *r, int x) {

    return r[x]==x ? x : r[x]=Find(r, r[x]);

}



void init() {

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

        ra[i]=ro[i]=i;

    }

}



vector <int> ve[200005];

map <int, int> ma;

int ans[200005];



int main () {

    int u, v;

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

    init();

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

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

        u=Find(ro, u), v=Find(ro, v);

        if(u!=v) {

            ro[u]=v;

        }

    }



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

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

        u=Find(ra, u), v=Find(ra, v);

        if(u!=v) {

            ra[u]=v;

        }

    }



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

        ve[Find(ro, i)].push_back(i);

    }



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

        ma.clear();

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

            ma[Find(ra, ve[i][j])]++;

        }



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

            ans[ve[i][j]]+=ma[Find(ra, ve[i][j])];

        }

    }



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

        printf("%d%c", ans[i], i==n ? '\n' : ' ');

    }

    return 0;

}

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

 

using namespace std;

 

typedef long long ll;

 

const int MAXN = 2e5+7;

const int Inf = 0x3f3f3f3f;

 

int pre1[MAXN],pre2[MAXN];

 

int finds(int x,int *pre)

{

    return pre[x] == x? pre[x]:pre[x] = finds(pre[x],pre);

}

 

void join(int x,int y,int *pre)

{

    int px = finds(x,pre);

    int py = finds(y,pre);

    if( px!=py)

    {

        pre[px] = py;

    }

}

int main()

{

    int n,k,l;

    cin>>n>>k>>l;

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

        pre1[i] = i,pre2[i] = i;

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

    {

        int x,y;

        cin>>x>>y;

        join(x,y,pre1);

    }

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

    {

        int x,y;

        cin>>x>>y;

        join(x,y,pre2);

    }

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

    {

        finds(i,pre1);

        finds(i,pre2);

    }

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

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

    {

        mp[make_pair(pre1[i],pre2[i])] ++;

    }

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

    {

        cout<<mp[make_pair(pre1[i],pre2[i])]<<" ";

    }

    cout<<endl;

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

#include<cstring>

#include<algorithm>

#include<set>

#include<map>

#define MAXN 200000

using namespace std;

typedef pair<int,int> PII;

map<PII,int> mp;

int setfa[2][MAXN+5];

void Init()

{

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

		setfa[0][i]=setfa[1][i]=i;

}

int Findfa(int x,int typ)

{

	if(setfa[typ][x]==x)

		return x;

	return setfa[typ][x]=Findfa(setfa[typ][x],typ);

}

void Union(int x,int y,int typ)

{

	int fx=Findfa(x,typ),fy=Findfa(y,typ);

	if(fx==fy)

		return;

	setfa[typ][fx]=fy;

}

int main()

{

	Init();

	int N,K,L;

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

	int x,y;

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

	{

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

		Union(x,y,0);

	}

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

	{

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

		Union(x,y,1);

	}

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

	{

		int a=Findfa(i,0),b=Findfa(i,1);

		mp[PII(a,b)]++;

	}

	int Ans;

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

	{

		int a=Findfa(i,0),b=Findfa(i,1);

		Ans=mp[PII(a,b)];

		if(i==1)

			printf("%d",Ans);

		else

			printf(" %d",Ans);

	}

	printf("\n");

	return 0;

}

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

 

using namespace std;

 

typedef long long ll;

 

const int MAXN = 2e5+7;

const int Inf = 0x3f3f3f3f;

 

int pre1[MAXN],pre2[MAXN];

 

int finds(int x,int *pre)

{

    return pre[x] == x? pre[x]:pre[x] = finds(pre[x],pre);

}

 

void join(int x,int y,int *pre)

{

    int px = finds(x,pre);

    int py = finds(y,pre);

    if( px!=py)

    {

        pre[px] = py;

    }

}

int main()

{

    int n,k,l;

    cin>>n>>k>>l;

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

        pre1[i] = i,pre2[i] = i;

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

    {

        int x,y;

        cin>>x>>y;

        join(x,y,pre1);

    }

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

    {

        int x,y;

        cin>>x>>y;

        join(x,y,pre2);

    }

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

    {

        finds(i,pre1);

        finds(i,pre2);

    }

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

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

    {

        mp[make_pair(pre1[i],pre2[i])] ++;

    }

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

    {

        cout<<mp[make_pair(pre1[i],pre2[i])]<<" ";

    }

    cout<<endl;

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

#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

#include <vector>

#include <map>

#define ms(x) memset(x, 0, sizeof(x))

#define inf 0x3f3f3f3f

using namespace std;

const int N = 200005;

vector<int >book[N];

int faf[N], fag[N];

int vis[N];

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

void init() {

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

        faf[i] = fag[i] = i;

    }

}

int Find(int *f, int x){

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

    else{

        f[x] = Find(f, f[x]);

        return f[x];

    }

}

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

    int a = Find(f, x) , b = Find(f, y);

    if(a!=b){

        f[b] = a;

    }

}

int main() {

    int n, k, l;

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

        int u, v;

        init();

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

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

            Merge(faf, u, v);

        }

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

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

            Merge(fag, u, v);

        }

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

            ++mp[{Find(faf, i), Find(fag, i)}];        //将同一个连通块中的点 集合起来

        }

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

            printf("%d%c", mp[{Find(faf, i), Find(fag, i)}],i==n?'\n':' ');

        }

    }

    return 0;

}


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

#include<cstdio>

#include<map>

#include<sstream>

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

const int maxn = 2e5+7;

int a[maxn];

int p[maxn],q[maxn],r[maxn];

int found1(int x)

{

    return x==p[x]?x : p[x] = found1(p[x]);

}

int found2(int x)

{

    return x==q[x]?x : q[x] = found2(q[x]);

}

int main()

{

    int n,l,k;

    cin >> n >> k >> l;

    int a,b;

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

    {

        p[i] = i;

        q[i] = i;

    }

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

    {

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

        int x = found1(a),y = found1(b);

        if(x!=y)

        {

            p[x] = y;

        }

    }

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

    {

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

        int x = found2(a),y = found2(b);

        if(x!=y)

        {

            q[x] = y;

        }

    }

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

    {

        found1(i);

        found2(i);

    }

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

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

    {

        mp[make_pair(p[i],q[i])]++;

    }

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

    {

        cout << mp[make_pair(p[i],q[i])] << " ";

    }

    cout <<endl;

    return 0;

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

#include <cmath>

#include <queue>

#include <stack>

#include <vector>

#include <cstdio>

#include <string>

#include <cstring>

#include <sstream>

#include <algorithm>



using namespace std;



int ro[200005], ra[200005], n, k, l;



int Find(int *r, int x) {

    return r[x]==x ? x : r[x]=Find(r, r[x]);

}



void init() {

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

        ra[i]=ro[i]=i;

    }

}



vector <int> ve[200005];

map <int, int> ma;

int ans[200005];



int main () {

    int u, v;

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

    init();

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

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

        u=Find(ro, u), v=Find(ro, v);

        if(u!=v) {

            ro[u]=v;

        }

    }



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

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

        u=Find(ra, u), v=Find(ra, v);

        if(u!=v) {

            ra[u]=v;

        }

    }



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

        ve[Find(ro, i)].push_back(i);

    }



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

        ma.clear();

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

            ma[Find(ra, ve[i][j])]++;

        }



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

            ans[ve[i][j]]+=ma[Find(ra, ve[i][j])];

        }

    }



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

        printf("%d%c", ans[i], i==n ? '\n' : ' ');

    }

    return 0;

}

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

#include<cstdio>

#include<map>

#include<sstream>

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

const int maxn = 2e5+7;

int a[maxn];

int p[maxn],q[maxn],r[maxn];

int found1(int x)

{

    return x==p[x]?x : p[x] = found1(p[x]);

}

int found2(int x)

{

    return x==q[x]?x : q[x] = found2(q[x]);

}

int main()

{

    int n,l,k;

    cin >> n >> k >> l;

    int a,b;

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

    {

        p[i] = i;

        q[i] = i;

    }

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

    {

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

        int x = found1(a),y = found1(b);

        if(x!=y)

        {

            p[x] = y;

        }

    }

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

    {

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

        int x = found2(a),y = found2(b);

        if(x!=y)

        {

            q[x] = y;

        }

    }

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

    {

        found1(i);

        found2(i);

    }

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

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

    {

        mp[make_pair(p[i],q[i])]++;

    }

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

    {

        cout << mp[make_pair(p[i],q[i])] << " ";

    }

    cout <<endl;

    return 0;

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

#include<cstring>

#include<algorithm>

#include<set>

#include<map>

#define MAXN 200000

using namespace std;

typedef pair<int,int> PII;

map<PII,int> mp;

int setfa[2][MAXN+5];

void Init()

{

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

		setfa[0][i]=setfa[1][i]=i;

}

int Findfa(int x,int typ)

{

	if(setfa[typ][x]==x)

		return x;

	return setfa[typ][x]=Findfa(setfa[typ][x],typ);

}

void Union(int x,int y,int typ)

{

	int fx=Findfa(x,typ),fy=Findfa(y,typ);

	if(fx==fy)

		return;

	setfa[typ][fx]=fy;

}

int main()

{

	Init();

	int N,K,L;

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

	int x,y;

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

	{

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

		Union(x,y,0);

	}

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

	{

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

		Union(x,y,1);

	}

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

	{

		int a=Findfa(i,0),b=Findfa(i,1);

		mp[PII(a,b)]++;

	}

	int Ans;

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

	{

		int a=Findfa(i,0),b=Findfa(i,1);

		Ans=mp[PII(a,b)];

		if(i==1)

			printf("%d",Ans);

		else

			printf(" %d",Ans);

	}

	printf("\n");

	return 0;

}

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

#include<cstdio>

#include<map>

#include<sstream>

#include<cstring>

#include<algorithm>

#include<string>

using namespace std;

const int maxn = 2e5+7;

int a[maxn];

int p[maxn],q[maxn],r[maxn];

int found1(int x)

{

    return x==p[x]?x : p[x] = found1(p[x]);

}

int found2(int x)

{

    return x==q[x]?x : q[x] = found2(q[x]);

}

int main()

{

    int n,l,k;

    cin >> n >> k >> l;

    int a,b;

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

    {

        p[i] = i;

        q[i] = i;

    }

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

    {

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

        int x = found1(a),y = found1(b);

        if(x!=y)

        {

            p[x] = y;

        }

    }

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

    {

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

        int x = found2(a),y = found2(b);

        if(x!=y)

        {

            q[x] = y;

        }

    }

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

    {

        found1(i);

        found2(i);

    }

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

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

    {

        mp[make_pair(p[i],q[i])]++;

    }

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

    {

        cout << mp[make_pair(p[i],q[i])] << " ";

    }

    cout <<endl;

    return 0;

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

#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

#include <vector>

#include <map>

#define ms(x) memset(x, 0, sizeof(x))

#define inf 0x3f3f3f3f

using namespace std;

const int N = 200005;

vector<int >book[N];

int faf[N], fag[N];

int vis[N];

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

void init() {

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

        faf[i] = fag[i] = i;

    }

}

int Find(int *f, int x){

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

    else{

        f[x] = Find(f, f[x]);

        return f[x];

    }

}

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

    int a = Find(f, x) , b = Find(f, y);

    if(a!=b){

        f[b] = a;

    }

}

int main() {

    int n, k, l;

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

        int u, v;

        init();

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

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

            Merge(faf, u, v);

        }

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

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

            Merge(fag, u, v);

        }

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

            ++mp[{Find(faf, i), Find(fag, i)}];        //将同一个连通块中的点 集合起来

        }

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

            printf("%d%c", mp[{Find(faf, i), Find(fag, i)}],i==n?'\n':' ');

        }

    }

    return 0;

}


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

#define pii pair<int,int>



using namespace std;



int pr[200005] , pr2[200005];

map<pii,int>mp;



int find(int u)

{

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

    return pr[u] = find(pr[u]);

}

int find2(int u)

{

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

    return pr2[u] = find2(pr2[u]);

}

int main()

{

    int n,m,r;

    cin >> n >> m >> r;

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

    {

        pr[i] = i;

        pr2[i] = i;

    }

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

    {

        int u,v;

        cin >> u >> v;

        int a,b;

        a = find(u);

        b = find(v);

        if(a > b)

            swap(a,b);

        pr[a] = b;

    }

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

    {

        int u,v;

        cin >> u >> v;

        int a,b;

        a = find2(u);

        b = find2(v);

        if(a > b)

            swap(a,b);

        pr2[a] = b;

    }

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

        mp[{find(i),find2(i)}]++;



    for(int i=1; i<=n; i++)cout << mp[{pr[i],pr2[i]}] << " ";

    cout << endl;

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

#include <cmath>

#include <queue>

#include <stack>

#include <vector>

#include <cstdio>

#include <string>

#include <cstring>

#include <sstream>

#include <algorithm>



using namespace std;



int ro[200005], ra[200005], n, k, l;



int Find(int *r, int x) {

    return r[x]==x ? x : r[x]=Find(r, r[x]);

}



void init() {

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

        ra[i]=ro[i]=i;

    }

}



vector <int> ve[200005];

map <int, int> ma;

int ans[200005];



int main () {

    int u, v;

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

    init();

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

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

        u=Find(ro, u), v=Find(ro, v);

        if(u!=v) {

            ro[u]=v;

        }

    }



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

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

        u=Find(ra, u), v=Find(ra, v);

        if(u!=v) {

            ra[u]=v;

        }

    }



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

        ve[Find(ro, i)].push_back(i);

    }



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

        ma.clear();

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

            ma[Find(ra, ve[i][j])]++;

        }



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

            ans[ve[i][j]]+=ma[Find(ra, ve[i][j])];

        }

    }



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

        printf("%d%c", ans[i], i==n ? '\n' : ' ');

    }

    return 0;

}

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

#define pii pair<int,int>



using namespace std;



int pr[200005] , pr2[200005];

map<pii,int>mp;



int find(int u)

{

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

    return pr[u] = find(pr[u]);

}

int find2(int u)

{

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

    return pr2[u] = find2(pr2[u]);

}

int main()

{

    int n,m,r;

    cin >> n >> m >> r;

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

    {

        pr[i] = i;

        pr2[i] = i;

    }

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

    {

        int u,v;

        cin >> u >> v;

        int a,b;

        a = find(u);

        b = find(v);

        if(a > b)

            swap(a,b);

        pr[a] = b;

    }

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

    {

        int u,v;

        cin >> u >> v;

        int a,b;

        a = find2(u);

        b = find2(v);

        if(a > b)

            swap(a,b);

        pr2[a] = b;

    }

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

        mp[{find(i),find2(i)}]++;



    for(int i=1; i<=n; i++)cout << mp[{pr[i],pr2[i]}] << " ";

    cout << endl;

}