PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000032. Liên thông bằng đường bộ và đường sắt (Connectivity)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Liên thông bằng đường bộ và đường sắt (Connectivity)

Connectivity

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn cities numbered from 11 to nn. The transportation system has kk roads and ll railway links. Every link is bidirectional, but the two transportation networks are considered separately.

Two cities are road-connected if one can travel between them using only roads. They are rail-connected if one can travel between them using only rail links. A city is always considered connected to itself, even if it has no incident links.

For each city ii, count the cities jj that are both road-connected and rail-connected to ii. The two journeys are considered independently and need not follow the same route.

Input

The first line contains n,k,ln,k,l; then kk road pairs pi,qip_i,q_i, followed by ll rail pairs ri,sir_i,s_i. Pairs are distinct within each network and endpoints are in ascending order.

Output

Print nn counts for the cities in order.

Subtasks

  • Subtask 1 (20 points): 2≤n≤252\le n\le25, 1≤k,l≤3001\le k,l\le300; 1≤pi<qi≤n1\le p_i<q_i\le n, 1≤ri<si≤n1\le r_i<s_i\le n; edges do not repeat within either network.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le2000, 1≤k,l≤1051\le k,l\le10^5; 1≤pi<qi≤n1\le p_i<q_i\le n, 1≤ri<si≤n1\le r_i<s_i\le n; edges do not repeat within either network.
  • Subtask 3 (50 points): 2≤n≤2⋅1052\le n\le2\cdot10^5, 1≤k,l≤1051\le k,l\le10^5; 1≤pi<qi≤n1\le p_i<q_i\le n, 1≤ri<si≤n1\le r_i<s_i\le n; edges do not repeat within either network.

Examples

Input

4 3 1
1 2
2 3
3 4
2 3

Output

1 2 2 1

Explanation

All four cities are connected by roads. By rail, only cities 22 and 33 are connected, while cities 11 and 44 are separate. The numbers of cities reachable by both modes are therefore 1 2 2 1.