luogu#P4918. 信仰收集
信仰收集
Background
As various forces moved in, Moriya Shrine lost quite a lot of faith.
Now, in order to bring back the shrine’s increasingly declining incense offerings, Yasaka Kanako sends the shrine’s wind priestess Sanae to the Human Village to collect faith.
Problem Description
You can view the village as a directed acyclic graph (DAG) with nodes. On some nodes there are clusters of faith to be collected (each cluster has a certain amount). The graph has directed edges, and each edge has length .
Sanae will start from node and may stop collecting at any node in the graph. When Sanae is at a node that has faith, she will collect all the faith on that node (including node ).
For convenience, Sanae learned teleportation from Usami Sumireko, so she can move units of length at a time (called a small teleport), or move units of length at a time (called a big teleport). These cost and spirit power respectively. It is guaranteed that , but since Gensokyo is not bound by common sense, is not necessarily less than .
Now, Sanae wants you to help her find the maximum possible value of (amount of faith collected spirit power cost) she can obtain in the village.
Input Format
The first line contains three integers , representing the number of nodes with faith, the total number of nodes, and the number of directed edges.
The second line contains two integers , representing the distances of the two types of teleport.
The third line contains two integers , representing the spirit power costs of the two types of teleport.
Then lines follow, each with two positive integers , representing the position of a faith cluster and the amount of faith in that cluster. It is not guaranteed that all are distinct.
Then lines follow, each with two integers , representing a directed edge from node to node .
Output Format
A single line containing one integer , representing the maximum value of (amount of faith collected spirit power cost).
3 7 8
1 2
3 2
2 2
4 3
6 4
1 2
2 4
4 5
2 6
7 6
6 4
3 2
3 4
2
Hint
Sample Explanation:
The graph is as shown below:

Node has faith, node has faith, and node has faith.
Sanae can teleport a distance of or edges, with costs and respectively.
One optimal plan is to teleport from node to node at a cost of , collect the faith at node , and then stop. Faith cost .
Constraints:

Translated by ChatGPT 5