#P2648. Unlimited Earnings in a City Tour
Unlimited Earnings in a City Tour
Unlimited Earnings in a City Tour
zzy is planning to tour China and earn money along the way. In each city, zzy can earn at most D yuan. After earning in a city, he can either retire (stop working) or move to another city to work again. He may even return to a city where he previously worked to earn another D yuan. There is no limit on the number of trips.
The country has C cities numbered from 1 to C. There are P one‐way roads connecting these cities. The ith road goes from city Ai to city Bi and does not incur any travel cost.
Besides roads, there are F one‐way flights available. The ith flight goes from city Ji to city Ki and costs Ti yuan. Even if zzy does not currently have enough cash, he can use money he will earn in the future to pay for the flight.
zzy can start working from any city and may choose to retire at any moment, in any city. With unlimited working time, determine the maximum amount of money zzy can earn. If he can earn an arbitrarily large amount of money, output \(\texttt{orz}\).
Note: Any formulas in this description are written in LaTeX. For example, the earning in a city is denoted by \(D\) and the net gain when taking a flight from city \(u\) to city \(v\) is \(D-T\).
inputFormat
The first line contains four space‐separated integers: \(C\), \(P\), \(F\), and \(D\), representing the number of cities, the number of roads, the number of flights, and the maximum amount of money that can be earned in one city, respectively.
The next \(P\) lines each contain two integers \(A\) and \(B\), indicating a one‐way road from city \(A\) to city \(B\>.
The following \(F\) lines each contain three integers \(J\), \(K\), and \(T\), indicating a one‐way flight from city \(J\) to city \(K\) with a cost of \(T\) yuan.
outputFormat
Output a single value representing the maximum money zzy can earn. If the amount is unbounded, output orz
.
sample
3 0 0 10
10
</p>