4. (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, and V
has certain constraints, characterized by A, entities each with B, resistance points. The
travel time to cross this road at time t depends on these constraints: it takes \lceil \frac{t}{A} \rceil + B
time units to overcome the entities and move on to city V, 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, 0 ? M ? 10<sup>6</sup>).
• The next M lines contain the description of the undirected roads.
• The i<sup>th</sup> (1 ? i ? M) line consists of U, V, B, A, (1 ? U, V ? N, 0 ? A, B, ?
10<sup>9</sup>).
Output:
• Print the minimum time possible according to the problem statement.
Examples
Input:
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
\lceil \frac{1}{0+1} \rceil + 2 - 3
units, where the division is integer division. Thus, the minimal travel time required to
reach city 2 is 3 units.
Input:
Output:
20
Hint:
• t<sub>xy</sub> = t<sub>x</sub> + \lceil \frac{t<sub>x</sub>}{A} \rceil + B<sub>i</sub>
• t<sub>x</sub> is the time when you depart from city ‘x’ for city ‘y’