#P9340. [JOIST 2023] 旅行 / Tourism
[JOIST 2023] 旅行 / Tourism
Description
JOI Kingdom is an insular country consisting of islands, numbered from to . The islands are connected by bridges, numbered from to . The bridge connects the island and the island bidirectionally. It is possible to travel from any island to any other island by passing through a number of bridges. In JOI Kingdom, there are sightseeing spots, numbered from to . The sightseeing spot is located in the island . There are travelers. They plan to visit sightseeing spots in JOI Kingdom. The travelers are numbered from to . Each traveler makes a trip in the following way.
-
The traveler chooses an island . Taking an airplane, the traveler arrives at the island .
-
The traveler takes the following actions a number of times. The order and the kinds of actions are arbitrary.
- The traveler chooses a sightseeing spot in the current island, and visits there.
- The traveler moves to another island by passing through a bridge.
-
Taking an airplane, the traveler leaves JOI Kingdom. The traveler wants to visit all of the sightseeing spots . However, since the budget is limited, the traveler wants to minimize the number of islands where the traveler visits at least once.
Write a program which, given information of JOI Kingdom and the travelers, calculates, for each , the minimum possible number of islands where the traveler visits at least once.
Input Format
Read the following data from the standard input.
Output Format
Write lines to the standard output. The -th line of output should contain the minimum possible number of islands where the traveler visits at least once.
7 6 2
1 2
1 3
2 4
2 5
3 6
3 7
2 3 6 4 5 7
1 3
4 6
4
6
8 8 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 6 4 3 5 2 4 7
3 5
4 6
6 8
1 4
2 3
6 8
5 5
2 8
1 2
3
4
6
6
3
6
1
6
3
10 7 9
6 5
3 6
9 3
8 3
7 8
7 1
2 5
7 10
8 4
9 4 10 1 10 7 6
4 4
1 3
1 3
6 7
3 6
3 3
1 5
2 5
1 2
1
6
6
4
3
1
7
5
4
Hint
【样例解释 #1】
The traveler 1 makes a trip in the following way, and visits all of the sightseeing spots 1, 2, 3.
- The traveler 1 arrives at the island 2.
- The traveler 1 visits the sightseeing spot 1 in the island 2.
- The traveler 1 moves from the island 2 to the island 1 by passing through the bridge 1.
- The traveler 1 moves from the island 1 to the island 3 by passing through the bridge 2.
- The traveler 1 visits the sightseeing spot 2 in the island 3.
- The traveler 1 moves from the island 3 to the island 6 by passing through the bridge 5.
- The traveler 1 visits the sightseeing spot 3 in the island 6.
- The traveler 1 departs from the island 6 and leaves JOI Kingdom.
The islands 1, 2, 3, 6 are the four islands where the traveler 1 visits at least once. If the number of islands traveler 1 visits at least once is less than or equal to 3, it is impossible to visit all of the sightseeing spots 1, 2, 3. Therefore, output 4 in the first line. The traveler 2 makes a trip in the following way, and visits all of the sightseeing spots 4, 5, 6.
- The traveler 2 arrives at the island 3.
- The traveler 2 moves from the island 3 to the island 7 by passing through the bridge 6.
- The traveler 2 visits the sightseeing spot 6 in the island 7.
- The traveler 2 moves from the island 7 to the island 3 by passing through the bridge 6.
- The traveler 2 moves from the island 3 to the island 1 by passing through the bridge 2.
- The traveler 2 moves from the island 1 to the island 2 by passing through the bridge 1.
- The traveler 2 moves from the island 2 to the island 4 by passing through the bridge 3.
- The traveler 2 visits the sightseeing spot 4 in the island 4.
- The traveler 2 moves from the island 4 to the island 2 by passing through the bridge 3.
- The traveler 2 moves from the island 2 to the island 5 by passing through the bridge 4.
- The traveler 2 visits the sightseeing spot 5 in the island 5.
- The traveler 2 departs from the island 5 and leaves JOI Kingdom.
The islands 1, 2, 3, 4, 5, 7 are the six islands where the traveler 2 visits at least once. If the number of islands traveler 2 visits at least once is less than or equal to 5, it is impossible to visit all of the sightseeing spots 4, 5, 6. Therefore, output 6 in the second line. This sample input satisfies the constraints of Subtasks 1, 2, 4, 5, 6.
The islands 1, 2, 3, 4, 5, 7 are the six islands where the traveler 2 visits at least once. If the number of islands traveler 2 visits at least once is less than or equal to 5, it is impossible to visit all of the sightseeing spots 4, 5, 6. Therefore, output 6 in the second line.
This sample input satisfies the constraints of Subtasks 1, 2, 4, 5, 6.
【样例解释 #2】
This sample input satisfies the constraints of Subtasks 1, 2, 3, 6.
【样例解释 #3】
This sample input satisfies the constraints of Subtasks 1, 2, 6.
【数据范围】
- .
- .
- .
- .
- .
- It is possible to travel from any island to any other island by passing through a number of bridges.
- .
- .
- Given values are all integers.
【子任务】
- (5 points) .
- (5 points) .
- (7 points) .
- (18 points) $L_1 = 1, R_{k} + 1 = L_{k+1}\ (1 ≤ k ≤ Q − 1), R_Q = M$.
- (24 points) $A_i = \lfloor\frac{i+1}2\rfloor, B_i = i + 1\ (1 ≤ i ≤ N−1)$. Here, is the largest integer not exceeding x.
- (41 points) No additional constraints.
京公网安备 11011102002149号