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 Python (2.7.6) (judge verdict: Wrong Answer)

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.141592653589
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

class UnionFind:
    def __init__(self, size):
        self.rank=[0]*size
        self.par =range(size)
        self.grp =size

    def find(self, x):
        if x==self.par[x]: return x

        self.par[x]=self.find(self.par[x])
        return self.par[x]

    def same(self, x, y): #2つの頂点が同じグループであるかを判定する
        return self.find(x)==self.find(y)

    def unite(self, x, y): #辺で接続されている2つの頂点を投げて統合する
        x,y=self.find(x),self.find(y)
        if x==y:
            return

        self.grp-=1
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def group_num(self):
        return self.grp
    def ra(self):
        return self.rank


class UnionFind2:
    def __init__(self, size2):
        self.rank2=[0]*size2
        self.par2 =range(size2)
        self.grp2 =size2

    def find(self, x2):
        if x2==self.par2[x2]: return x2

        self.par2[x2]=self.find(self.par2[x2])
        return self.par2[x2]

    def same(self, x2, y2): #2つの頂点が同じグループであるかを判定する
        return self.find(x2)==self.find(y2)

    def unite(self, x2, y2): #辺で接続されている2つの頂点を投げて統合する
        x,y=self.find(x2),self.find(y2)
        if x2==y2:
            return

        self.grp2-=1
        if self.rank2[x2]<self.rank2[y2]:
            self.par2[x2]=y2
        else:
            self.par2[y2]=x2
            if self.rank2[x2]==self.rank2[y2]:
                self.rank2[x2]+=1

    def group_num(self):
        return self.grp2
    def ra(self):
        return self.rank2



n,k,l=map(int,raw_input().split())
uf=UnionFind(n)
uf2=UnionFind2(n)
q1,q2=[],[]
ans=[0]*n
for i in range(k):
    a,b=map(int,raw_input().split())
    uf.unite(a-1,b-1)
    q1.append((a-1,b-1))
    ans[a-1]=1
    ans[b-1]=1

for i in range(l):
    a,b=map(int,raw_input().split())
    uf2.unite(a-1,b-1)
    if ans[a-1]==0: ans[a-1]=1
    if ans[b-1]==0: ans[b-1]=1
    if uf.same(a-1,b-1):
        ans[a-1]=2
        ans[b-1]=2

for i in q1:
    if uf2.same(i[0],i[1]):
        ans[i[0]]=2
        ans[i[1]]=2
print ' '.join(map(str,ans))