#USACO2437. 哞路线II

哞路线II

Bessie is on vacation! Due to some recent technological advances, Bessie will travel via technologically sophisticated flights, which can even time travel. Furthermore, there are no issues if two "parallel" versions of Bessie ever meet.

In the country there are NN airports numbered 1,2,,N1,2,…,N and MM time-traveling flights (1N,M200000)(1≤N,M≤200000). Flight jj leaves airport cjc_j at time rjr_j, and arrives in airport djd_j at time sj(0rj,sj109,sj<rj is possible)s_j(0≤r_j,s_j≤10^9, s_j<r_j\ is\ possible). In addition, she must leave aia_i time for a layover at airport ii (1ai109)(1≤a_i≤10^9). (That is to say, if Bessie takes a flight arriving in airport ii at time ss, she can then transfer to a flight leaving the airport at time rr if rr+air≥r+a_i. The layovers do not affect when Bessie arrives at an airport.)

Bessie starts at city 1 at time 0. For each airport from 1 to NN, what is the earliest time when Bessie can get to at it?

INPUT FORMAT (input arrives from the terminal / stdin):

The first line of input contains NN and MM.The next MM lines describe flights. The JJth of these lines contains cj,rj,dj,sjc_j,r_j,d_j,s_j in that order. (1cj,djN,0rj,sj109)(1≤c_j,d_j≤N, 0≤r_j,s_j≤10^9)

The next line describes airports. It contains NN space separated integers, a1,a2...aNa_1,a_2...a_N.

OUTPUT FORMAT (print output to the terminal / stdout):

There are NN lines of output. Line ii contains the earliest time when Bessie can get to airport ii, or -1 if it is not possible for Bessie to get to that airport.

3 3
1 0 2 10
2 11 2 0
2 1 3 20
10 1 10
0
0
20

Bessie can take the 3 flights in the listed order, which allows her to arrive at airports 1 and 2 at time 0, and airport 3 at time 20.

Note that this route passes through airport 2 twice, first from time 10-11 and then from time 0-1.

3 3
1 0 2 10
2 10 2 0
2 1 3 20
10 1 10
0
10
-1

In this case, Bessie can take flight 1, arriving at airport 2 at time 10. However, she does not arrive in time to also take flight 2, since the departure time is 10 and she cannot make a 1 time-unit layover.

SCORING:

  • Inputs 3-5: r_j<s_j for all jj, i.e. all flights arrive after they depart.
  • Inputs 6-10: N,M5000N,M≤5000
  • Inputs 11-20: No additional constraints.