loj#P2308. 「APIO2017」商旅

「APIO2017」商旅

Description

After many days' journey through the great Australian outback, you have finally arrived at the great city of Cobar with nothing but a small backpack. Enamoured by the wonder and beauty of its markets, you decide to become a merchant and make Cobar your new home. Cobar has NN markets, numbered from 11 to NN, connected by MM one-way footpaths, each taking a particular number of minutes to walk along.

The markets of Cobar trade in KK different items, numbered from 11 to KK. Each market has a fixed price for buying or selling each item. Not every market will trade in every item, and it is possible that for any given item, a market may only support buying it, but not selling it, or vice-versa. You may assume that each market that has a given item for sale has an infinite quantity of it available, and similarly, if a market wants to buy a given item, it is willing to buy it repeatedly, forever.

To earn money as quickly as possible, you would like to find the most efficient profit cycle. A profit cycle is a walk through Cobar that starts at some market vv with your backpack empty, continues along Cobar's footpaths and through its markets (possibly buying and selling items along the way), and finally returns to vv, again with an empty backpack. It may visit a market and/or walk along a footpath multiple times. Once an item is bought, it must be placed immediately in your backpack and since your backpack is small, it can only hold up to a single item at any point in time. You may assume that you are always able to buy an item if it is available, regardless of the amount of money you possess so far and that you are prohibited from selling an item that you do not possess.

The profit earned from such a cycle is the total amount of money you earned from selling items, minus the total amount of money you spent buying them. The duration of a cycle is the total number of minutes you spend walking along its constituent footpaths. The efficiency of a profit cycle is the profit earned from it, divided by its duration. Note that a profit cycle that does not involve buying or selling any items has an efficiency of 00.

Your task is to find the maximum efficiency among all profit cycles with strictly positive duration. You should report this value rounded down, to the nearest integer. If no such profit cycle exists, you should report 0.

Input

Your program should read from standard input.

The first line will contain 3 integers, NN, MM and KK: the number of markets, footpaths and items respectively.

NN lines follow. The ith of these lines contains 2K2K integers Bi,1,B_{i,1}, Si,1,S_{i,1}, Bi,2,B_{i,2}, Si,2,S_{i,2}, ,\ldots, Bi,K,B_{i,K}, Si,KS_{i,K} describing a market. For all 1jK1 ≤ j ≤ K, the pair of integers Bi,jB_{i,j} and Si,jS_{i,j} describe the price at which you can buy and sell item jj at market ii, respectively. If an item cannot be bought or sold, then -1 will be used as a placeholder.

MM lines follow. The pth of these contains 3 integers, VpV_p, WpW_p and TpT_p, describing a one-way footpath from market VpV_p to another market WpW_p, taking TpT_p minutes to traverse.

Output

Your program should write to standard output.

Print a single integer, the maximum efficiency among all profit cycles, rounded down to the nearest integer.

4 5 2
10 9 5 2
6 4 20 15
9 7 10 9
-1 -1 16 11
1 2 3
2 3 3
1 4 1
4 3 1
3 1 1
2

Limits And Hints

For all subtasks,

  • 1N100,1 ≤ N ≤ 100, 1M9,900,1 ≤ M ≤ 9,900, 1K1000,1 ≤ K ≤ 1000,
  • and for all items which can be bought/sold, 0<Si,jBi,j1090 < S_{i,j} ≤ Bi,j ≤ 10^9 for all 1iN1 ≤ i ≤ N and for all 1jK1 ≤ j ≤ K.
  • Additionally, VpWpV_p ≠ W_p and 1Tp1071 ≤ T_p ≤ 10^7 for all 1pM1 ≤ p ≤ M,
  • and there does not exist any pair of edges 1p<qM1 ≤ p < q ≤ M such that (Vp,Wp)=(Vq,Wq)(Vp, Wp) = (Vq, Wq).
Subtask Points Additional Constraints Description
11 1212 Bi,j=1 (2iN,1jK)B_{i,j}=-1\ (2\le i\le N,1\le j\le K) You can only buy items from market 1.
22 2121 N,K50,Tp=1 (1pM)N,K\le 50,T_p=1\ (1\le p\le M) All footpaths take 1 minute to travel along.
33 3333 Bi,j=Si,j1 (1iN,1jK)B_{i,j}=S_{i,j}\neq -1\ (1\le i\le N,1\le j\le K) Each market buys and sells every item, and the buying price of an item is equal to its selling price at any given market (it may be different between markets).
44 3434 None. No further constraints.