stablegradients/pie-gem5-pairs huggingface dataset:
// 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()

{

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

{

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

#include<cstring>

#include<algorithm>

#include<map>

using namespace std;

const int N=2e5+5;

int f1[N],f2[N];

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]);

}

map<pair<int,int>,int>p;

int main()

{

    int n,k,l;

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

        int u,v;

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

        int a=find1(u),b=find1(v);

        f1[a]=b;

    }

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

        int u,v;

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

        int a=find2(u),b=find2(v);

        f2[a]=b;

    }

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

        p[make_pair(find1(i),find2(i))]++;

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

        printf("%d ",p[make_pair(f1[i],f2[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: 10.502090040946987x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<map>

using namespace std;

const int N=2e5+5;

int f1[N],f2[N];

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]);

}

map<pair<int,int>,int>p;

int main()

{

    int n,k,l;

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

        int u,v;

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

        int a=find1(u),b=find1(v);

        f1[a]=b;

    }

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

        int u,v;

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

        int a=find2(u),b=find2(v);

        f2[a]=b;

    }

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

        p[make_pair(find1(i),find2(i))]++;

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

        printf("%d ",p[make_pair(f1[i],f2[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.9308662999901636x):
#include<cstdio>

#include<vector>

#include<cstring>

#include<map>

#include<algorithm>

using namespace std;

const int MAXN=200005;

int n,k,l,fa[MAXN],zfa[MAXN];

map<pair<int,int>,int>M;

int find(int x)

{

	if(fa[x]==x)

		return x;

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

}

int zfind(int x)

{

	if(zfa[x]==x)

		return x;

	return zfa[x]=zfind(zfa[x]);

}

struct node

{

	int u,v;

	node(){}

}A[MAXN];

int main()

{

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

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

		fa[i]=zfa[i]=i;

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

	{

		int u,v;

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

		int a=find(u),b=find(v);

		if(a!=b)

		{

			fa[a]=b;

		}

	}

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

	{

		scanf("%d %d",&A[i].u,&A[i].v);

		int a=zfind(A[i].u),b=zfind(A[i].v);

		if(a!=b)

		{

			zfa[a]=b;

		}

	}

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

	{

		pair<int,int> c;

		c.first=find(i);

		c.second=zfind(i);

		M[c]++;

	}

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

	{

		pair<int,int> c;

		c.first=find(i);

		c.second=zfind(i);

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

	}

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

#include<vector>

#include<cstring>

#include<map>

#include<algorithm>

using namespace std;

const int MAXN=200005;

int n,k,l,fa[MAXN],zfa[MAXN];

map<pair<int,int>,int>M;

int find(int x)

{

	if(fa[x]==x)

		return x;

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

}

int zfind(int x)

{

	if(zfa[x]==x)

		return x;

	return zfa[x]=zfind(zfa[x]);

}

struct node

{

	int u,v;

	node(){}

}A[MAXN];

int main()

{

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

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

		fa[i]=zfa[i]=i;

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

	{

		int u,v;

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

		int a=find(u),b=find(v);

		if(a!=b)

		{

			fa[a]=b;

		}

	}

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

	{

		scanf("%d %d",&A[i].u,&A[i].v);

		int a=zfind(A[i].u),b=zfind(A[i].v);

		if(a!=b)

		{

			zfa[a]=b;

		}

	}

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

	{

		pair<int,int> c;

		c.first=find(i);

		c.second=zfind(i);

		M[c]++;

	}

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

	{

		pair<int,int> c;

		c.first=find(i);

		c.second=zfind(i);

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

	}

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

#include<map>

#define maxn 200005

using namespace std;

int n,m,k,f[maxn],scc[maxn],x,y;

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

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

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

int main()

{

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

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

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

	{

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

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

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

	}

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

	{

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

		x=f2(x),y=f2(y);

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

	}

	for(int i=1;i<=n;i++) f[i]=find(f[i]),scc[i]=f2(scc[i]);

	for(int i=1;i<=n;i++) cnt[make_pair(f[i],scc[i])]++;

	for(int i=1;i<=n;i++) printf("%d ",cnt[make_pair(f[i],scc[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: 10.50193115102555x):
#include<cstdio>

#include<map>

#define maxn 200005

using namespace std;

int n,m,k,f[maxn],scc[maxn],x,y;

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

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

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

int main()

{

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

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

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

	{

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

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

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

	}

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

	{

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

		x=f2(x),y=f2(y);

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

	}

	for(int i=1;i<=n;i++) f[i]=find(f[i]),scc[i]=f2(scc[i]);

	for(int i=1;i<=n;i++) cnt[make_pair(f[i],scc[i])]++;

	for(int i=1;i<=n;i++) printf("%d ",cnt[make_pair(f[i],scc[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.796420927995132x):
#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;



int N,K,L,u,v,cnt[202018];

long long bb[4][202018];



int zbb(int i,int c)

{

	return bb[c][i]==i?i:bb[c][i]=zbb(bb[c][i],c);

}



int main()

{

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

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

		bb[0][i]=i,bb[1][i]=i,bb[2][i]=i,bb[3][i]=i;

		

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

	{

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

		int p=zbb(u,0),q=zbb(v,0);

		if(p!=q) bb[0][q]=p;

	}

	

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

	{

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

		int p=zbb(u,1),q=zbb(v,1);

		if(p!=q) bb[1][q]=p;

	}

	

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

		bb[2][i]=bb[3][i]=zbb(bb[0][i],0)+1LL*zbb(bb[1][i],1)*(N+1);

	

	sort(bb[3]+1,bb[3]+1+N);

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

	{

		int pos=lower_bound(bb[3]+1,bb[3]+1+N,bb[2][i])-bb[3];

		cnt[pos]++;

	}

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

	{

		int pos=lower_bound(bb[3]+1,bb[3]+1+N,bb[2][i])-bb[3];

		cout<<cnt[pos]<<' ';

	}

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

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;



int N,K,L,u,v,cnt[202018];

long long bb[4][202018];



int zbb(int i,int c)

{

	return bb[c][i]==i?i:bb[c][i]=zbb(bb[c][i],c);

}



int main()

{

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

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

		bb[0][i]=i,bb[1][i]=i,bb[2][i]=i,bb[3][i]=i;

		

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

	{

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

		int p=zbb(u,0),q=zbb(v,0);

		if(p!=q) bb[0][q]=p;

	}

	

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

	{

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

		int p=zbb(u,1),q=zbb(v,1);

		if(p!=q) bb[1][q]=p;

	}

	

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

		bb[2][i]=bb[3][i]=zbb(bb[0][i],0)+1LL*zbb(bb[1][i],1)*(N+1);

	

	sort(bb[3]+1,bb[3]+1+N);

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

	{

		int pos=lower_bound(bb[3]+1,bb[3]+1+N,bb[2][i])-bb[3];

		cnt[pos]++;

	}

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

	{

		int pos=lower_bound(bb[3]+1,bb[3]+1+N,bb[2][i])-bb[3];

		cout<<cnt[pos]<<' ';

	}

}