#ARC065B. [ABC049D] 連結

[ABC049D] 連結

Score : 400400 points

Problem Statement

There are NN cities. There are also KK roads and LL railways, extending between the cities. The ii-th road bidirectionally connects the pip_i-th and qiq_i-th cities, and the ii-th railway bidirectionally connects the rir_i-th and sis_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 AA and BB are connected by roads if city BB is reachable from city AA 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

  • 2N21052 \leq N \leq 2*10^5
  • 1K,L1051 \leq K, L \leq 10^5
  • 1pi,qi,ri,siN1 \leq p_i, q_i, r_i, s_i \leq N
  • pi<qip_i < q_i
  • ri<sir_i < s_i
  • When iji \neq j, (pi,qi)(pj,qj)(p_i, q_i) \neq (p_j, q_j)
  • When iji \neq j, (ri,si)(rj,sj)(r_i, s_i) \neq (r_j, s_j)

Input

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

NN KK LL

p1p_1 q1q_1

:

pKp_K qKq_K

r1r_1 s1s_1

:

rLr_L sLs_L

Output

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

4 3 1
1 2
2 3
3 4
2 3
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,21, 2, 2 and 11, respectively.

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