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 Fortran (gfortran v4.8.4) (judge verdict: Wrong Answer)

module mod1
implicit none
integer(8) :: par(200000),par2(200000),par_total(200000),num(200000),ans(200000)=0
end module mod1

program test
use mod1
implicit none
integer(8) :: n,i,j,k,l,last,kind
integer(8) :: p(100000),q(100000),r(100000),s(100000)

read(*,*) n,k,l
!道路
do i=1,k
	read(*,*) p(i),q(i)
enddo
!鉄道
do i=1,l
	read(*,*) r(i),s(i)
enddo

do i=1,n
	par(i) = i
	par2(i) = i
enddo

!道路
do i=1,k
	call unite(p(i),q(i))
enddo

!鉄道
do i=1,l
	call unite2(r(i),s(i))
enddo

do i=1,n
	num(i) = i
	par_total(i) = 1000000*par(i) + par2(i)
enddo

call heapsort2(n,par_total(1:n),num(1:n))

!種類を数える！
do i=1,n
	if(i==1) then
		last=1
		kind=1
	else if(par_total(i) .eq. par_total(i-1)) then 
		kind = kind + 1
	else
		do j = last,i-1
			ans(num(j)) = ans(num(j)) + kind
		enddo
		kind = 1
		last = i
	endif
	
	!最後の処理
	if(i==n) then
		do j = last,i
			ans(num(j)) = ans(num(j)) + kind
		enddo
	endif
enddo

write(*,*) ans(1:n)

contains
!道路
recursive function root(x) result(res)
integer(8) :: x,res
	if(par(x) == x) then
		continue
	else
		par(x) = root(par(x))
	endif
	res = par(x)
end function

subroutine unite(x,y)
integer(8) :: x,y
x = root(x)
y = root(y)
if(x > y) then
	par(x) = y
	par(y) = y
else if (x < y) then
	par(y) = x
	par(x) = x
endif
end subroutine


!鉄道
recursive function root2(x) result(res)
integer(8) :: x,res
	if(par2(x) == x) then
		continue
	else
		par2(x) = root2(par2(x))
	endif
	res = par2(x)
end function

subroutine unite2(x,y)
integer(8) :: x,y
x = root2(x)
y = root2(y)
if(x > y) then
	par(x) = y
	par(y) = y
else if (x < y) then
	par(y) = x
	par(x) = x
endif
end subroutine

subroutine heapsort2(n,y1,y2)

	implicit none
	integer(8),intent(in) :: n
	integer(8),intent(inout) :: y1(1:n)
	integer(8),intent(inout) :: y2(1:n)
	integer(8) :: i,k,j,l
	integer(8) :: t1,t2
	
	l = n/2+1
	k = n

	do while (k /= 1)
		 if(l > 1) then
				l = l-1
				t1 = y1(l)
				t2 = y2(l)
				
		 else
				t1 = y1(k)
				t2 = y2(k)
				y1(k) = y1(1)
				y2(k) = y2(1)
				k = k-1
				if(k == 1) then
					 y1(1) = t1
					 y2(1) = t2
					 exit
				endif
		 endif

		 i = l
		 j = l+l

		 do while(j <= k)
				if(j < k) then
					 if(y1(j) < y1(j+1)) j = j+1
				endif
				
				if (t1 < y1(j)) then
					 y1(i) = y1(j)
					 y2(i) = y2(j)
					 i = j
					 j = j+j
				else
					 j = k+1
				endif
		 
		 enddo
		 
		 y1(i) = t1
		 y2(i) = t2
	
	enddo
	return

end subroutine heapsort2

end program test