Under construction

Still being built. Things may change

Cyberland

Time limit7sMemory limit1024 MB

Summary
Find the minimum time from country 0 to country H when some countries zero the passing time or halve it, with at most K halvings.
Level

Hard8 of 10

Topics
Shortest path, Dynamic programming, Graph, Heap
Solved
No attempts yet

Problem

The year 3742 has arrived, and now it is Cyberland's turn to host the APIO. In this world, there are NN countries indexed from 00 to N−1N - 1, along with MM bidirectional roads (allowing travel in both directions) indexed from 00 to M−1M - 1. The ii-th road (0≤i<M0 \le i < M) connects two different countries, x[i]x[i] and y[i]y[i], and requires a certain amount of time c[i]c[i] to pass the road. All participants have gathered in Cyberland for the APIO, except for your country. You are living in country 00, and Cyberland is country HH. As the cleverest person in your country, your assistance is urgently needed once again. To be more specific, you are asked to determine the minimum time required to reach Cyberland from your country. Some countries can clear your total passing time. Also, some countries can divide your total passing time by 22 (divide-by-22 ability). You can visit a country repeatedly. Every time you visit a country, you may choose whether to use the special ability in the country. But you can use the special ability at most once in a single visit (which means that special ability can be used multiple times by visiting the country multiple times). Moreover, you can only use the divide-by-22 ability at most KK times in case of being caught by Cyberland Chemistry Foundation. Once you reached Cyberland, you cannot move anywhere because the great APIO contest will be held soon. An array arrarr is given, where arriarr_i (0≤i<N0 \le i < N) shows the special abilities of country ii. There are 33 types of special abilities: arri=0arr_i = 0 means this country makes the passing time 00. arri=1arr_i = 1 means the passing time remains unchanged at this country. arri=2arr_i = 2 means this country divides the passing time by 22. It is guaranteed that arr0=arrH=1arr_0 = arr_H = 1 holds. In other words, Cyberland and your country do not have any special abilities. Your country does not want to miss any moment of APIO, so you need to find the minimum time to reach Cyberland. If you cannot reach Cyberland, your answer should be −1-1.

Constraints

2≤N≤1052 \le N \le 10^5, and ∑N≤105\sum N \le 10^5. 0≤M≤min⁡{105,N(N−1)2}0 \le M \le \min\{10^5, \frac{N(N-1)}{2}\}, and ∑M≤105\sum M \le 10^5. 1≤K≤1061 \le K \le 10^6. 1≤H<N1 \le H < N. 0≤x[i],y[i]<N0 \le x[i], y[i] < N, and x[i]≠y[i]x[i] \ne y[i]. 1≤c[i]≤1091 \le c[i] \le 10^9. arr[i]∈{0,1,2}arr[i] \in \{0, 1, 2\}. It is guaranteed that every pair of countries is connected by at most one road.

Examples1

  1. Example 1

    Input
    1
    2 0 1 1
    1 1
    
    Expected output
    -1