(10 points) You need to travel from city 1 to city N across a land divided into N cities connected by M undirected roads. Each road i (1 <= i <= M) between cities U_i and V_i has certain constraints, characterized by A_i entities each with B_i resistance points. The travel time to cross this road at time t depends on these constraints: it takes |_(_())(A_i)/(i+1)|+B_i time units to overcome the entities and move on to city V_i, where the division is done using integer division. You can start your journey at time 0 or any integer time unit thereafter, and you can wait at any city for any integer amount of time. The goal is to minimize the overall journey time. If it is not possible to reach city N, the result should be -1. The task is to find the minimum time required to complete your journey.
Input:
First line of input consists of N and M (2 <= N <= 10^5, 0 <= M <= 10^5).
The next M lines contain the description of the undirected roads.
The i-th (1 <= i <= M) line consists of U_i, V_i, A_i, B_i (1 <= U_i, V_i <= N, 0 <= A_i, B_i <= 10^9).
Output:
Print the minimum time possible according to the problem statement.
Examples:
Input:
3 2
1 2 1 2
1 3 1 3
Output:
3
By selecting the second road that links city 1 to city 2 and initiating the journey from city 1 at time t = 0, you can arrive in city 2 with a calculated time of |_(_())(1)/(1+1)|+2 = 3 units, where the division is integer division. Thus, the minimal travel time required to reach city 2 is 3 units.
Input:
3 2
1 2 16 1
1 3 4 10
Output:
20
Hint: t_y = t_x + |_(_())(A_i)/(i+1)| + B_i; t_x is the time when you depart from city 'x' for city 'y'.