atcoder#ARC065B. [ABC049D] 連結
[ABC049D] 連結
Score : points
Problem Statement
There are cities. There are also roads and railways, extending between the cities. The -th road bidirectionally connects the -th and -th cities, and the -th railway bidirectionally connects the -th and -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 and are connected by roads if city is reachable from city 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
- When ,
- When ,
Input
The input is given from Standard Input in the following format:
:
:
Output
Print integers. The -th of them should represent the number of the cities connected to the -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 and , 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