#P82. [CSP-S 2022] Holiday plan
[CSP-S 2022] Holiday plan
Person in Charge
Problem Description
There are points on Little Bear's map, where point numbered is its home and points numbered are all scenic spots. There are bidirectional direct bus routes between some pairs of points. If there are direct routes between point and , and , , and , and , then we say that and are reachable with exactly transfers. In particular, if there is a direct route between and , they are reachable with transfers.
The holiday is coming soon. Little Bear plans to start from home and visit distinct scenic spots, completing trips and then returning home, following the route: $\text{Home} \to \text{Scenic Spot A} \to \text{Scenic Spot B} \to \text{Scenic Spot C} \to \text{Scenic Spot D} \to \text{Home}$. Each trip is allowed to have at most transfers. There are no restrictions on the points passed during transfers — they can be the home, scenic spots, or even points that are repeatedly traversed. For example, during the trip from Scenic Spot A to Scenic Spot B, the points passed during transfers can be the home, Scenic Spot C, or even the points passed during the transfer of the trip from Scenic Spot D to home.
Each scenic spot has a score. Please help Little Bear plan the trip such that the sum of the scores of the distinct scenic spots visited is maximized.
Input Format
The first line contains three positive integers , representing the number of points on the map, the number of pairs of points connected by direct bidirectional routes, and the maximum number of transfers allowed for each trip respectively.
The second line contains positive integers, denoting the scores of the scenic spots numbered in order.
The next lines each contain two positive integers , indicating that there is a direct bidirectional route between point and point . It is guaranteed that , with no duplicate edges or self-loops.
Output Format
Output a positive integer, representing the maximum sum of the scores of the distinct scenic spots that Little Bear visits in a valid trip.
Samples
8 8 1
9 7 1 8 2 3 6
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
27
7 9 0
1 1 1 2 3 4
1 2
2 3
3 4
1 5
1 6
1 7
5 4
6 4
7 4
7
Sample (1) Explanation
When the planned trip is , the sum of the scores of the 4 scenic spots is , which is proven to be the maximum possible value.
The sum of scores for the trip is , and for is . Both trips satisfy the requirements but yield a smaller sum of scores.
The sum of scores for the trip is , yet the trip from to requires at least transfers, which violates the constraint of at most transfer.
The sum of scores for the trip is , but it does not visit distinct scenic spots and thus fails to meet the requirement.
Sample (3)
See holiday/holiday3.in and holiday/holiday3.ans in the contestant's directory.
Data Range
For all test data, it is guaranteed that , , , and the score of each scenic spot satisfies . It is guaranteed that there exists at least one valid trip.
| Test Case No. | |||
|---|---|---|---|