Problem:
Score : 400 points

Problem Statement

There are N cities. There are also K roads and L railways, extending between the cities.
The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities.
No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.

We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads.
We will also define connectivity by railways similarly.

For each city, find the number of the cities connected to that city by both roads and railways.

Constraints

2 ≦ N ≦ 2*10^5

1 ≦ K, L≦ 10^5

1 ≦ p_i, q_i, r_i, s_i ≦ N

p_i < q_i

r_i < s_i

When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)

When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)

Input

The input is given from Standard Input in the following format:

N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L

Output

Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.

Sample Input 1

4 3 1
1 2
2 3
3 4
2 3

Sample Output 1

1 2 2 1

All the four cities are connected to each other by roads.

By railways, only the second and third cities are connected. Thus, the answers for the cities are 1, 2, 2 and 1, respectively.

Sample Input 2

4 2 2
1 2
2 3
1 4
2 3

Sample Output 2

1 2 2 1

Sample Input 3

7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7

Sample Output 3

1 1 2 1 2 2 2

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#pragma comment(linker, "/stack:200000000")
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
 
#include <bits/stdc++.h>
 
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;
#define y1 sfasfd 
using namespace std;
 
mt19937 mrand(random_device{}()); 
const ll mod = 1e9 + 7;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
 
typedef pair < int , int > pii ;
const int N = 4e5 + 123;
int n , t , p[5][N] , Sz[5][N];
int u[N] , v[N];
int get(int t , int a){
	if(a == p[t][a])
		return a;
	return p[t][a] = get(t , p[t][a]);	
}
void unite(int t , int a , int b){
	a = get(t , a) , b = get(t , b);
	if(a == b)
		return;
	if(Sz[t][a] < Sz[t][b])
		swap(a , b);
	Sz[t][a] += Sz[t][b];
	p[t][b] = a;
	return;
}

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

	for(int i = 1 ; i <= n ;i++)
		p[1][i] = p[2][i] = p[3][i] =i , Sz[1][i] = Sz[2][i] = Sz[3][i] = 1;
	
	for(int i = 1 ; i <= k ; i++){
		scanf("%d%d" , &u[i] , &v[i]);
		unite(1 , u[i] , v[i]);
	}
	for(int j = 1 , i = k + 1; j <= l ; j++ , i++){
		scanf("%d%d" , &u[i] , &v[i]);
		unite(2 , u[i] , v[i]);
	}
	int brute = 1e6;
	while(brute--){
		int x = rnd(n) + 1 , y = rnd(n) + 1;
		if(get(1 , x) == get(1 , y) && get(2 , x) == get(2 , y))
			unite(3 , x , y);
	}
	brute = 1e6;
	while(brute--){
		int i = rnd(k + l) + 1;
		if(get(1 , u[i]) == get(1 , v[i]) && get(2 , u[i]) == get(2 , v[i]))
			unite(3 , u[i] , v[i]);
	}
	for(int i = 1 ; i <= k + l ; i ++ ){
		if(get(1 , u[i]) == get(1 , v[i]) && get(2 , u[i]) == get(2 , v[i]))
			unite(3 , u[i] , v[i]);
	}
	for(int i = 1; i <= n ; i++)
		printf("%d " , Sz[3][get(3 , i)]);
}