#P8817. [CSP-S 2022] 假期计划
[CSP-S 2022] 假期计划
Problem Description
There are points on Little Bear’s map. Point is its home, and points are all scenic spots. Between some pairs of points, there are bidirectional direct bus lines. If there are direct lines between and , between and , , between and , and between and , then we say that the trip from to can be completed with transfers. In particular, if there is a direct line between and , then it can be completed with transfers.
The holiday is coming soon. Little Bear plans to start from home and visit different scenic spots, then return home after completing segments of travel: home spot A spot B spot C spot D home. Each segment may use at most transfers. There are no restrictions on the points passed during transfers: they can be home, scenic spots, and the same point may be passed multiple times. For example, in the segment from spot A spot B, the points passed during transfers can include home, or spot C, and they may even include points that are passed during transfers in the segment spot D home.
Assume each scenic spot has a score. Please help Little Bear plan a route so that the sum of the scores of the four different scenic spots it visits is maximized.
Input Format
The first line contains three integers , representing the number of points on the map, the number of bidirectional directly connected pairs, and the maximum number of transfers allowed for each segment.
The second line contains positive integers, representing the scores of scenic spots numbered .
The next lines each contain two positive integers , indicating that points and are directly connected by a road. It is guaranteed that , and there are no multiple edges or self-loops.
Output Format
Output one positive integer, the maximum possible sum of the scores of the different scenic spots that Little Bear visits.
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
Hint
[Sample Explanation #1]
When the planned route is , the sum of the scores of the scenic spots is . It can be proven that this is the maximum.
The sum of scenic spot scores for the route is , and for the route is . They both meet the requirements, but their sums are not the maximum.
The sum of scenic spot scores for the route is , but in it, requires at least transfers, so it does not satisfy the requirement of at most transfer.
The sum of scenic spot scores for the route is , but the trip does not visit different scenic spots, so it also does not meet the requirements.
[Sample #3]
See holiday/holiday3.in and holiday/holiday3.ans in the attachment.
[Constraints]
For all testdata, it is guaranteed that , , , and for all scenic spots, . It is guaranteed that there exists at least one route that meets the requirements.
| Test Point ID | |||
|---|---|---|---|
Translated by ChatGPT 5