#P6603. 「EZEC-2」甜梦

「EZEC-2」甜梦

Description

There are nn dream scenes, with distinct indices in [1,n][1,n]. PF has schizophrenia, so at the same time he will be in two dreams. The absolute difference between the indices of the scenes where these two dreams are located must not exceed ll. Between scenes there are mm directed relations. The ii-th relation connects scenes uiu_i and viv_i. There is no scene that is impossible to reach.

Each scene has a happiness value. The happiness value of scene jj is aja_j, which is added when the dream passes through it for the first time.

At the beginning, both dreams are at scene 11. When both dreams move to scene nn, PF will wake up.

If in some move, the two scenes A,BA,B where PF’s dreams are currently located are both directly connected to some scene CC, then PF can move both dreams simultaneously to scene CC. Otherwise, PF can only move one dream at a time.

Please write a program to compute the maximum total happiness value that can be obtained when he wakes up.

Input Format

The first line contains three integers n,m,ln,m,l, representing the number of scenes, the number of relations between scenes, and the maximum allowed distance between PF’s two scenes.

The next line contains nn integers. The ii-th number means the happiness value of scene ii is aia_i. The happiness values of scene 11 and scene nn are 00.

The next mm lines each contain two integers u,v(1u<vn)u,v(1\le u<v \le n), indicating that there is a directed relation between the scenes.

Output Format

If there is a solution, output one integer qq in one line, meaning the maximum happiness value obtainable.

If there is no solution, output -1.

7 9 2
0 4 5 10 10 20 0
1 2
1 3
1 4
1 6
2 5
3 5
4 7
5 7
6 7
25

Hint

Large sample

[Sample Explanation #1]

Below, A,BA,B denote the two dreams currently in progress:

Move dream A 13A \space 1 \to 3, move dream B 14B \space 1 \to 4, move dream A 35A \space 3 \to 5, then move dreams A BA \space B simultaneously to scene 77. The total happiness value is 5+10+10=255+10+10 = 25.

Note: If you want to move one dream to scene 66, then the other dream’s index must be greater than or equal to 44. However, the only route to 66 is 161\to 6, and having scenes 11 and 44 at the same time does not satisfy having intermediate scenes l\le l. Therefore, the only way to pass through scene 66 is to move both dreams to scene 66 simultaneously, and the happiness value you can get in that case is 2020.


[Constraints and Conventions] | Test Point ID | n n \le | m m \le | l l \le | ai a_i \le | Time | Special Property | | :----------: | :----------: | :----------: | :----------: |:----------: | :----------: |:----------: | | 1,21,2 | 1010 | 1515| 55 | 5050 | 1s1\text s | None | | 343\sim 4 | 1616 | 4040 | 88 | 5×1035 \times 10^3 | 1s1\text s | None | | 565\sim 6 | 1616 | 120120 | 88 | 5×1035 \times 10^3 | 1s1\text s | None | | 7107 \sim 10 | 100100 | 10310^3 | 1010 | 10410^4 | 1s1 \text s | None | | 1111 | 100100 | 10310^3 | 1010 | 10410^4 | 1s1\text s | The scenes form a tree | | 121412 \sim 14 | 10310^3 | 10410^4 | 1010 | 10410^4 | 1s1\text s | None | | 15,1615,16 | 5×1035\times10^3 | 3×1043\times10^4 | 1010 | 10410^4 | 1s1\text s | None | | 17,1817,18 | 5×1035\times10^3 | 3×1043\times10^4 | 1111 | 10410^4 | 2s2\text s | None | | 19,2019,20 | 5×1035\times10^3 | 3×1043\times10^4 | 1212 | 10410^4 | 3s3\text s | None |

For 100%100\% of the testdata, 1u<vn1\le u<v \le n, 1n5×1031 \le n \le 5\times 10^3, 1m3×1041 \le m \le 3\times 10^4, 1ai1041 \le a_i \le 10^4, 1l121 \le l \le 12.

The input guarantees that every scene can be reached from the start, and every scene can reach the end.

The input does not guarantee that there are no multiple edges.

The input makes no guarantee about the difference between the indices of u,vu,v.


[Movement Examples]

Assume l=2l=2 and the relations exist. The following format represents one move: A BA \space B \to A BA' \space B'.

  • 1 35 31 \space 3 \to 5\space 3 (√)
  • 1 31 41 \space 3 \to 1\space 4 (×)
  • 1 38 81 \space 3 \to 8\space 8 (√)
  • 1 36 81 \space 3 \to 6\space 8 (×)

Translated by ChatGPT 5