#P2648. 赚钱

赚钱

Description

zzy now decides to travel around China and make some money along the way. In any single visit to a city, zzy can earn at most DD yuan. After that, he may choose to retire (i.e., stop earning) or go to other cities to work. Of course, he can work elsewhere for a while and then return to the original city to earn another DD yuan. The number of such round trips is unlimited.

There are PP directed paths between cities, and there are CC cities in total, numbered from 11 to CC. Path ii goes from city AiA_i to city BiB_i, and traveling along these paths costs nothing.

zzy can also take a flight from one city to another. There are FF directed flights; the ii-th flight goes from city JiJ_i to city KiK_i with a cost of TiT_i yuan. If zzy has no cash on hand, he can pay the airfare with money he will earn in the future.

zzy may start earning from any city and may retire at any time and in any city. Now zzy wants to know: if there is no limit on working time, how much money can he earn in total? If the amount he can earn has no limit, output orz.

Input Format

The first line contains 44 space-separated positive integers D,P,C,FD,P,C,F.

Lines 22 to P+1P+1 each contain 22 space-separated integers Ai,BiA_i,B_i, describing a directed path from city AiA_i to city BiB_i.

The next FF lines each contain 33 space-separated positive integers Ji,Ki,TiJ_i,K_i,T_i, describing a directed flight from city JiJ_i to city KiK_i with a cost of TiT_i.

Output Format

If the amount zzy can earn is unbounded, output orz. Otherwise, output the maximum amount of money zzy can earn under the given rules.

100 3 5 2
1 5
2 3
1 4
5 2 150
2 5 120
250

Hint

For 100%100\% of the testdata, 1D10001\le D\le 1000, 1P2001\le P\le 200, 2C3002\le C\le 300, 1F4001\le F\le 400, 1Ti10001\le T_i \le 1000.

Translated by ChatGPT 5