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 mm nodes. On some nodes there are nn clusters of faith to be collected (each cluster has a certain amount). The graph has kk directed edges, and each edge has length 11.

Sanae will start from node 11 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 11).

For convenience, Sanae learned teleportation from Usami Sumireko, so she can move aa units of length at a time (called a small teleport), or move bb units of length at a time (called a big teleport). These cost waw_a and wbw_b spirit power respectively. It is guaranteed that aba \le b, but since Gensokyo is not bound by common sense, waw_a is not necessarily less than wbw_b.

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 n,m,kn,m,k, representing the number of nodes with faith, the total number of nodes, and the number of directed edges.

The second line contains two integers a,ba,b, representing the distances of the two types of teleport.

The third line contains two integers wa,wbw_a,w_b, representing the spirit power costs of the two types of teleport.

Then nn lines follow, each with two positive integers pos,tpos,t, representing the position of a faith cluster and the amount of faith in that cluster. It is not guaranteed that all pospos are distinct.

Then kk lines follow, each with two integers u,vu,v, representing a directed edge from node uu to node vv.

Output Format

A single line containing one integer xx, 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 22 has 22 faith, node 44 has 33 faith, and node 66 has 44 faith.

Sanae can teleport a distance of 11 or 22 edges, with costs 33 and 22 respectively.

One optimal plan is to teleport from node 11 to node 66 at a cost of 22, collect the 44 faith at node 66, and then stop. Faith - cost =2= 2.

Constraints:

Translated by ChatGPT 5