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

# UnionFind
class UnionFind(object):
    # 親を表す配列 木はこの配列で表現する
    par = []
    rank = []

    def __init__(self, arg):
        super(UnionFind, self).__init__()
        self.par = [i for i in range(arg)]
        self.rank = [0 for i in range(arg)]

    # 木の根を求める
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # xとyの属する集合を結合
    def unite(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)

        if root_x == root_y:
            return

        if self.rank[root_x] > self.rank[root_y]:
            self.par[root_y] = root_x
        else:
            self.par[root_x] = root_y
            # それぞれの高さが一致する場合のみrankを更新する
            if self.rank[root_x] == self.rank[root_y]:
                self.rank[root_y] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


N, K, L = map(lambda x: int(x), input().split())

road_ways = []
rail_ways = []

for _ in range(K):
    road_ways.append(list(map(lambda x: int(x) - 1, input().split())))
for _ in range(L):
    rail_ways.append(list(map(lambda x: int(x) - 1, input().split())))
print(road_ways, rail_ways)

# 道路、鉄道を記録するUnionFind宣言
road_unionfind = UnionFind(N)
rail_unionfind = UnionFind(N)

# UnionFindを鉄道、道路それぞれで作成
for k in range(K):
    road_unionfind.unite(road_ways[k][0], road_ways[k][1])
for l in range(L):
    rail_unionfind.unite(rail_ways[l][0], rail_ways[l][1])

ans = [0 for _ in range(N)]
for n in range(N):
    # 自分自身は必ず一致しているので１スタート
    sum = 0
    for k in range(N):
        # 鉄道、道路のどちらでも繋がっているならインクリメント
        if road_unionfind.same(n, k) and rail_unionfind.same(n, k):
            sum += 1
    ans[n] = sum

print(*ans)