No.2739 Time is money
Problem Statement
There are $N$ towns connected by $M$ roads.
Using the $i \ (1 \leq i \leq M)$-th road, you can travel in both directions between town $u_i$ and town $v_i$.
Using this road costs a toll of $C_i$ yen, and traveling along it takes $T_i$ hours.
In town $1$ you can work, and you earn $X$ yen for every $1$ hour of work.
Anything other than traveling along roads and working takes $0$ time.
You are currently in town $1$ and have $0$ yen.
When traveling from town $1$ to town $N$ as quickly as possible, what is the minimum number of hours until you reach town $N$?
If it is impossible to travel to town $N$, print -1.
Constraints
- All input values are integers.
- $2 \leq N \leq 2 \times 10^5$
- $1 \leq M \leq 2 \times 10^5$
- $1 \leq X \leq 2 \times 10^5$
- $1 \leq u_i, v_i \leq N \ (1 \leq i \leq M)$
- $1 \leq C_i, T_i \leq 2 \times 10^5 \ (1 \leq i \leq M)$
Input
The input is given from standard input in the following format.
$N \ M \ X$ $u_1\ v_1\ C_1\ T_1$ $u_2\ v_2\ C_2\ T_2$ $\vdots$ $u_M\ v_M\ C_M\ T_M$
Output
If it is impossible to travel from town $1$ to town $N$, print -1.
Otherwise, print the minimum time required to travel to town $N$.
Sample
Sample 1
Input
5 6 10 1 3 7 2 4 1 2 5 3 4 1 3 2 3 5 4 4 5 6 8 2 5 4 1
Output
9
The fastest way is to work for $2$ hours in town $1$ and then travel through town $1$, town $3$, town $2$, town $5$ in this order.
Sample 2
Input
3 3 1 1 1 100 100 3 2 1 1 2 3 1 1
Output
-1
It is impossible to move out of town $1$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。