No.3111 Toll Optimization
Problem Statement
There are $N$ towns and $M$ bridges. The $i$-th bridge connects town $u_i$ and town $v_i$, can be crossed in either direction, and costs $C_i$ yen to cross.
You have $K$ coupons. By using one coupon when crossing a bridge, you can make the toll for crossing that bridge $0$ yen.
You are currently in town $1$ and want to go to town $N$. Find the minimum toll you must pay when using the coupons optimally.
Constraints
- $2 \leq N,M \leq 10^5$
- $0 \leq K \leq 3$
- $1 \leq u_i<v_i \leq N$
- $1 \leq C_i \leq 10^9$
- $i \neq j \Rightarrow (u_i,v_i) \neq (u_j,v_j)$
Input
The input is given from standard input in the following format.
$N\ M\ K$ $C_1\ C_2\ldots\ C_M$ $u_1\ v_1$ $u_2\ v_2$ $\vdots$ $u_M\ v_M$
Output
Print on one line the minimum toll required to reach town $N$. However, if town $N$ cannot be reached, print $-1$. End the output with a newline.
Sample
Sample 1
Input
3 2 1 4 2 1 2 2 3
Output
2
By moving as follows, you can reach town $N$ for 2 yen.
- Move from town $1$ to $2$ using a coupon.
- Move from town $2$ to $3$ without using a coupon.
It can be proved that there is no way to reach town $N$ for less than $2$ yen, so the answer is $2$.
Sample 2
Input
5 4 2 4 2 3 9 1 2 2 3 1 3 4 5
Output
-1
Town $N$ cannot be reached.
Sample 3
Input
7 10 1 565731850 55598766 527171038 341219331 325504904 409516626 583498624 3987342 112468674 114000403 1 4 1 5 1 6 2 3 2 4 3 4 3 5 5 7 5 6 6 7
Output
3987342
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。