#P5508. 寻宝

寻宝

Description

This maze has a total of nn caves. There are many one-way tunnels between the caves, so many that it is hard to count them.

However, after analysis, it is found that:

These tunnels can be divided into mm groups. For each group, for every cave with an index in the interval [sl,sr][s_l,s_r], and every cave with an index in the interval [tl,tr][t_l,t_r], there is a tunnel between them. Each group contains a total of (srsl+1)(trtl+1)(s_r-s_l+1)\cdot (t_r-t_l+1) tunnels, and the time to pass through any tunnel in the same group is the same.

To further save time, Steve can dig new tunnels.

However, each cave has different properties, which makes digging tunnels of different difficulty. Some caves cannot even dig tunnels.

Specifically, the ii-th cave has a value viv_i. vi=0v_i=0 means tunnels cannot be dug from it. For other values, it means that starting from cave ii, digging a tunnel to cave jj and arriving at cave jj costs ijvi|i-j|*v_i time.

Steve wants to reach cave nn in the shortest time, and decides not to limit the number of tunnels he digs.

Now, you need to tell Steve the minimum time required.

If possible, you should help Steve find an optimal plan.

Input Format

The first line contains two integers n,mn,m.

The next line contains nn integers v1,v2,...,vnv_1,v_2,...,v_n.

The next mm lines each describe a group of tunnels.

Each line contains 55 integers sl,sr,tl,tr,ws_l,s_r,t_l,t_r,w, where ww is the travel time.

Output Format

If there is no solution, output only one line with one integer 1-1.

If there is a solution, output in the following format:

The first line contains an integer tt, which is the minimum time spent.

If you cannot provide a plan, output an integer 00 on the second line.

If you can provide a plan, output an integer cc on the second line, and output cc integers on the third line, representing (in order) the cave indices visited by one optimal plan.

You do not need to tell Steve whether each tunnel used is dug, or which group it belongs to.

6 2
0 1 2 0 0 0
1 1 2 3 5
4 5 6 6 2

9
3
1 2 6
6 2
0 1 2 0 0 0
1 1 2 3 5
4 5 6 6 2

9
4
1 3 4 6

Hint

Sample 1: From cave 11 to cave 22 use the first group tunnel, then from cave 22 to cave 66 dig a tunnel, costing 1(62)=41*(6-2)=4 time.

Sample 2: From cave 11 to cave 33 use the first group tunnel, then from cave 33 to cave 44 dig a tunnel, costing 2(43)=22*(4-3)=2, then from cave 44 to cave 66 use the second group tunnel.

Each subtask includes two test points, and the lower score is taken.

For each test point:

If the output format is wrong, then this test point scores 00.

If you do not output the correct time, then this test point scores 00.

If you output the correct time but do not give a plan, then you can get half of the score of this test point (the score of each test point is rounded down).

If you give a wrong plan, then you may get half of the score of this test point, or get 00.

If you give a correct plan, then you can get the full score of this test point.

The two outputs above can both get full score. Another plan is 12461 2 4 6.

If you output:

9
0

then you can get half of the score for this test point.

Constraints:

1w,vi1091\le w,v_i \le 10^9.

Subtask Score n m Special Property
1 5 100
2 10 3000
3 11 50000 50000 2,3
4 10 1
5 12 0
6 1
7 13 20 3
8
9 14 50000

Special Property 1: All vi=0v_i=0.

Special Property 2: All vi{0,k}v_i \in \{0,k\}, where kk is a constant.

Special Property 3: All sl=sr,tl=trs_l=s_r,t_l=t_r.

It is guaranteed that there exists a plan to reach cave nn.

About outputting a wrong plan:

If the output satisfies 2cn2\leq c\leq n, the visited nodes start with 11 and end with nn, and all intermediate nodes are integers in (1,n)(1,n), then this set of output may be an optimal solution, and you can get half of the score.

Otherwise, you get 00.

Do not worry about the SPJ TLE/MLE.

Translated by ChatGPT 5