#P8817. [CSP-S 2022] 假期计划

    ID: 9613 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2022O2优化广度优先搜索 BFSCSP-S 提高级

[CSP-S 2022] 假期计划

Problem Description

There are nn points on Little Bear’s map. Point 11 is its home, and points 2,3,,n2, 3, \ldots, n are all scenic spots. Between some pairs of points, there are bidirectional direct bus lines. If there are direct lines between xx and z1z_1, between z1z_1 and z2z_2, \ldots, between zk1z_{k - 1} and zkz_k, and between zkz_k and yy, then we say that the trip from xx to yy can be completed with kk transfers. In particular, if there is a direct line between xx and yy, then it can be completed with 00 transfers.

The holiday is coming soon. Little Bear plans to start from home and visit 44 different scenic spots, then return home after completing 55 segments of travel: home \to spot A \to spot B \to spot C \to spot D \to home. Each segment may use at most kk 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 \to 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 \to 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 n,m,kn, m, k, 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 n1n - 1 positive integers, representing the scores of scenic spots numbered 2,3,,n2, 3, \ldots, n.

The next mm lines each contain two positive integers x,yx, y, indicating that points xx and yy are directly connected by a road. It is guaranteed that 1x,yn1 \le x, y \le n, and there are no multiple edges or self-loops.

Output Format

Output one positive integer, the maximum possible sum of the scores of the 44 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 1235711 \to 2 \to 3 \to 5 \to 7 \to 1, the sum of the scores of the 44 scenic spots is 9+7+8+3=279 + 7 + 8 + 3 = 27. It can be proven that this is the maximum.

The sum of scenic spot scores for the route 1357811 \to 3 \to 5 \to 7 \to 8 \to 1 is 2424, and for the route 1328711 \to 3 \to 2 \to 8 \to 7 \to 1 is 2525. They both meet the requirements, but their sums are not the maximum.

The sum of scenic spot scores for the route 1235811 \to 2 \to 3 \to 5 \to 8 \to 1 is 3030, but in it, 585 \to 8 requires at least 22 transfers, so it does not satisfy the requirement of at most k=1k = 1 transfer.

The sum of scenic spot scores for the route 1232311 \to 2 \to 3 \to 2 \to 3 \to 1 is 3232, but the trip does not visit 44 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 5n25005 \le n \le 2500, 1m100001 \le m \le 10000, 0k1000 \le k \le 100, and for all scenic spots, 1si10181 \le s_i \le {10}^{18}. It is guaranteed that there exists at least one route that meets the requirements.

Test Point ID nn \le mm \le kk \le
131 \sim 3 1010 2020 00
454 \sim 5 55
686 \sim 8 2020 5050 100100
9119 \sim 11 300300 10001000 00
121412 \sim 14 100100
151715 \sim 17 25002500 1000010000 00
182018 \sim 20 100100

Translated by ChatGPT 5