#P6603. 「EZEC-2」甜梦
「EZEC-2」甜梦
Description
There are dream scenes, with distinct indices in . 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 . Between scenes there are directed relations. The -th relation connects scenes and . There is no scene that is impossible to reach.
Each scene has a happiness value. The happiness value of scene is , which is added when the dream passes through it for the first time.
At the beginning, both dreams are at scene . When both dreams move to scene , PF will wake up.
If in some move, the two scenes where PF’s dreams are currently located are both directly connected to some scene , then PF can move both dreams simultaneously to scene . 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 , 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 integers. The -th number means the happiness value of scene is . The happiness values of scene and scene are .
The next lines each contain two integers , indicating that there is a directed relation between the scenes.
Output Format
If there is a solution, output one integer 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
[Sample Explanation #1]

Below, denote the two dreams currently in progress:
Move dream , move dream , move dream , then move dreams simultaneously to scene . The total happiness value is .
Note: If you want to move one dream to scene , then the other dream’s index must be greater than or equal to . However, the only route to is , and having scenes and at the same time does not satisfy having intermediate scenes . Therefore, the only way to pass through scene is to move both dreams to scene simultaneously, and the happiness value you can get in that case is .
[Constraints and Conventions] | Test Point ID | | | | | Time | Special Property | | :----------: | :----------: | :----------: | :----------: |:----------: | :----------: |:----------: | | | | | | | | None | | | | | | | | None | | | | | | | | None | | | | | | | | None | | | | | | | | The scenes form a tree | | | | | | | | None | | | | | | | | None | | | | | | | | None | | | | | | | | None |
For of the testdata, , , , , .
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 .
[Movement Examples]
Assume and the relations exist. The following format represents one move: .
- (√)
- (×)
- (√)
- (×)
Translated by ChatGPT 5
京公网安备 11011102002149号