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

using namespace std;

int par1[200001],par2[200001];

vector<pair<int,int>> idx;

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

int rep1(int n)

{

    if(par1[n]==n)

        return n;

    return par1[n]=rep1(par1[n]);

}

int rep2(int n)

{

    if(par2[n]==n)

        return n;

    return par2[n]=rep2(par2[n]);

}

int main()

{

    int i,j;

    int n,k,l;

    int a,b,res=0;

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

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

        par1[i]=i;

        par2[i]=i;

    }

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

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

        int r1=rep1(a);

        int r2=rep1(b);

        par1[r1]=r2;

    }

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

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

        int r1=rep2(a);

        int r2=rep2(b);

        par2[r1]=r2;

    }

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

        idx.push_back(make_pair(rep1(i),rep2(i)));

    }

    /*

    sort(idx.begin(),idx.end());

    set<pair<int,int>> temp;

    for(i=0;i<idx.size();i++){

        temp.insert(idx[i]);

        cnt[idx[i]]++;

        //printf("%d %d\n",idx[i].first,idx[i].second);

    }

    for(auto itr: temp){

        res+=(cnt[itr])*(cnt[itr]);

    }

    */

    for(i=0;i<idx.size();i++){

        cnt[idx[i]]++;

        //printf("%d %d\n",idx[i].first,idx[i].second);

    }

    for(i=0;i<idx.size();i++)

        printf("%d ",cnt[idx[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.752932845398524x):
#include<bits/stdc++.h>

using namespace std;

int par1[200001],par2[200001];

vector<pair<int,int>> idx;

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

int rep1(int n)

{

    if(par1[n]==n)

        return n;

    return par1[n]=rep1(par1[n]);

}

int rep2(int n)

{

    if(par2[n]==n)

        return n;

    return par2[n]=rep2(par2[n]);

}

int main()

{

    int i,j;

    int n,k,l;

    int a,b,res=0;

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

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

        par1[i]=i;

        par2[i]=i;

    }

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

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

        int r1=rep1(a);

        int r2=rep1(b);

        par1[r1]=r2;

    }

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

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

        int r1=rep2(a);

        int r2=rep2(b);

        par2[r1]=r2;

    }

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

        idx.push_back(make_pair(rep1(i),rep2(i)));

    }

    /*

    sort(idx.begin(),idx.end());

    set<pair<int,int>> temp;

    for(i=0;i<idx.size();i++){

        temp.insert(idx[i]);

        cnt[idx[i]]++;

        //printf("%d %d\n",idx[i].first,idx[i].second);

    }

    for(auto itr: temp){

        res+=(cnt[itr])*(cnt[itr]);

    }

    */

    for(i=0;i<idx.size();i++){

        cnt[idx[i]]++;

        //printf("%d %d\n",idx[i].first,idx[i].second);

    }

    for(i=0;i<idx.size();i++)

        printf("%d ",cnt[idx[i]]);

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

using namespace std;

int par1[200001],par2[200001];

vector<pair<int,int>> idx;

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

int rep1(int n)

{

    if(par1[n]==n)

        return n;

    return par1[n]=rep1(par1[n]);

}

int rep2(int n)

{

    if(par2[n]==n)

        return n;

    return par2[n]=rep2(par2[n]);

}

int main()

{

    int i,j;

    int n,k,l;

    int a,b,res=0;

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

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

        par1[i]=i;

        par2[i]=i;

    }

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

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

        int r1=rep1(a);

        int r2=rep1(b);

        par1[r1]=r2;

    }

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

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

        int r1=rep2(a);

        int r2=rep2(b);

        par2[r1]=r2;

    }

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

        idx.push_back(make_pair(rep1(i),rep2(i)));

    }

    /*

    sort(idx.begin(),idx.end());

    set<pair<int,int>> temp;

    for(i=0;i<idx.size();i++){

        temp.insert(idx[i]);

        cnt[idx[i]]++;

        //printf("%d %d\n",idx[i].first,idx[i].second);

    }

    for(auto itr: temp){

        res+=(cnt[itr])*(cnt[itr]);

    }

    */

    for(i=0;i<idx.size();i++){

        cnt[idx[i]]++;

        //printf("%d %d\n",idx[i].first,idx[i].second);

    }

    for(i=0;i<idx.size();i++)

        printf("%d ",cnt[idx[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.7937566434541516x):
#include<bits/stdc++.h>

using namespace std;

int Arr[ 200005 ] , Brr[ 200005 ];

int A[ 200005 ] , B[ 200005 ];



void _init( int a )

{

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

    {

        Arr[ i ] = Brr[ i ] = i;

    }

}



int _roadfp( int a )

{

    if( Arr[ a ] == a )

        return a;

    return Arr[ a ] = _roadfp( Arr[ a ] );

}



int _railfp( int a )

{

    if( Brr[ a ] == a )

        return a;

    return Brr[ a ] = _railfp( Brr[ a ] );

}



void _roaduni( int x , int y )

{

    int u = _roadfp( x );

    int v = _roadfp( y );



    if( u != v )

    {

        Arr[ v ] = u;

    }

}



void _railuni( int x , int y )

{

    int u = _railfp( x );

    int v = _railfp( y );



    if( u != v )

    {

        Brr[ v ] = u;

    }

}



int main()

{

    int n , k , l;

    cin >> n >> k >> l;

    _init( n );



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

    {

        int a , b;

        cin >> a >> b;

        _roaduni( a , b );

    }



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

    {

        int a , b;

        cin >> a >> b;

        _railuni( a , b );

    }



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

    {

        _roadfp( i );

        _railfp( i );

    }



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



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

    {

        // cout << Arr[ i ] << "  " << Brr[ i ] << endl;

        M[ { Arr[ i ] , Brr[ i ] }  ] ++;

    }

//

//    for( auto it : M )

//    {

//        cout << it.first.first << " " << it.first.second << endl;

//        cout << it.second << endl;

//    }



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

    {

        printf("%d " , M[ { Arr[ i ] , Brr[ i ] } ] );

    }

    printf("%d\n" , M[ { Arr[ n ] , Brr[ 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.794643368801078x):
#include<bits/stdc++.h>

using namespace std;

int par1[200001],par2[200001];

vector<pair<int,int>> idx;

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

int rep1(int n)

{

    if(par1[n]==n)

        return n;

    return par1[n]=rep1(par1[n]);

}

int rep2(int n)

{

    if(par2[n]==n)

        return n;

    return par2[n]=rep2(par2[n]);

}

int main()

{

    int i,j;

    int n,k,l;

    int a,b,res=0;

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

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

        par1[i]=i;

        par2[i]=i;

    }

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

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

        if(i%2)swap(a,b);

        int r1=rep1(a);

        int r2=rep1(b);

        par1[r1]=r2;

    }

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

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

        int r1=rep2(a);

        int r2=rep2(b);

        par2[r1]=r2;

    }

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

        idx.push_back(make_pair(rep1(i),rep2(i)));

    }



    for(i=0;i<idx.size();i++){

        cnt[idx[i]]++;

        //printf("%d %d\n",idx[i].first,idx[i].second);

    }

    for(i=0;i<idx.size();i++)

        printf("%d ",cnt[idx[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.752228476897105x):
#include<bits/stdc++.h>

using namespace std;

int par1[200001],par2[200001];

vector<pair<int,int>> idx;

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

int rep1(int n)

{

    if(par1[n]==n)

        return n;

    return par1[n]=rep1(par1[n]);

}

int rep2(int n)

{

    if(par2[n]==n)

        return n;

    return par2[n]=rep2(par2[n]);

}

int main()

{

    int i,j;

    int n,k,l;

    int a,b,res=0;

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

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

        par1[i]=i;

        par2[i]=i;

    }

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

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

        if(i%2)swap(a,b);

        int r1=rep1(a);

        int r2=rep1(b);

        par1[r1]=r2;

    }

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

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

        int r1=rep2(a);

        int r2=rep2(b);

        par2[r1]=r2;

    }

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

        idx.push_back(make_pair(rep1(i),rep2(i)));

    }



    for(i=0;i<idx.size();i++){

        cnt[idx[i]]++;

        //printf("%d %d\n",idx[i].first,idx[i].second);

    }

    for(i=0;i<idx.size();i++)

        printf("%d ",cnt[idx[i]]);

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

using namespace std;

int par1[200001],par2[200001];

vector<pair<int,int>> idx;

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

int rep1(int n)

{

    if(par1[n]==n)

        return n;

    return par1[n]=rep1(par1[n]);

}

int rep2(int n)

{

    if(par2[n]==n)

        return n;

    return par2[n]=rep2(par2[n]);

}

int main()

{

    int i,j;

    int n,k,l;

    int a,b,res=0;

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

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

        par1[i]=i;

        par2[i]=i;

    }

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

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

        if(i%2)swap(a,b);

        int r1=rep1(a);

        int r2=rep1(b);

        par1[r1]=r2;

    }

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

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

        int r1=rep2(a);

        int r2=rep2(b);

        par2[r1]=r2;

    }

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

        idx.push_back(make_pair(rep1(i),rep2(i)));

    }



    for(i=0;i<idx.size();i++){

        cnt[idx[i]]++;

        //printf("%d %d\n",idx[i].first,idx[i].second);

    }

    for(i=0;i<idx.size();i++)

        printf("%d ",cnt[idx[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.752699011018407x):
#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;

#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.52429964851568x):
#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;

}