#P5769. [JSOI2016] 飞机调度

[JSOI2016] 飞机调度

Description

In the JSOI Kingdom, there are NN airports, numbered from 11 to NN. Flying from airport ii to airport jj takes time Ti,jT_{i,j}. Due to wind direction, geographic location, and air traffic control, Ti,jT_{i,j} and Tj,iT_{j,i} are not necessarily the same.

Also, after an aircraft lands, it needs routine maintenance and refueling. When an aircraft lands at airport kk, it must spend PkP_k time on maintenance before it can take off again.

JS Airways operates a total of MM routes. For the ii-th direct flight, it must take off from airport XiX_i at time DiD_i and fly non-stop to airport YiY_i.

To simplify the problem, we assume JS Airways can place any number of fully maintained and refueled aircraft at any airport at time 00. To reduce the number of aircraft used, we also allow JS Airways to add any number of temporary flights to satisfy scheduling needs.

JYY wants to know: in theory, what is the minimum number of aircraft JS Airways needs to complete all these MM flights.

Input Format

The first line contains two positive integers N,MN, M.

The next line contains NN positive integers, representing the aircraft maintenance time for each airport.

The next NN lines each contain NN non-negative integers. The jj-th non-negative integer in the ii-th line is Ti,jT_{i,j}, meaning the time required to fly from airport ii to airport jj. The data guarantees Ti,i=0T_{i,i} = 0.

The next MM lines each contain three positive integers. The ii-th line is Xi,Yi,DiX_i, Y_i, D_i, representing the departure airport, the arrival airport, and the departure time of the ii-th route. The data guarantees XiYiX_i \neq Y_i.

Output Format

Output one positive integer in a single line, representing the theoretical minimum number of aircraft JS Airways needs.

3 3
100 1 1
0 1 1
1 0 5
2 1 0
1 2 1
2 1 1
3 1 9

2

3 3
100 1 1
0 1 1
1 0 5
2 1 0
1 2 1
2 1 1
3 1 8

3

Hint

Sample Explanation 1

In the first sample, JS Airways can arrange one aircraft at airport 22 at time 00 and use it to operate flight 22 (212 \to 1). In addition, it needs to arrange one aircraft at airport 11 at time 00. This aircraft first operates flight 11 (121 \to 2), then takes a newly added temporary flight from airport 22 to airport 33, and after landing at airport 33, it operates flight 33 (313 \to 1).

Sample Explanation 2

In the second sample, the aircraft that finishes flight 11 cannot catch the departure time of flight 33. Therefore, JS Airways must use 33 different aircraft to complete all flights.


Constraints

For 30%30\% of the testdata, N,M10N, M \le 10.

For 60%60\% of the testdata, N,M100N, M \le 100.

For all testdata, 1N,M5001 \le N, M \le 500, 0Pi,Ti,j1060 \le P_i, T_{i,j} \le 10^6, 1Di1061 \le D_i \le 10^6.

Translated by ChatGPT 5