Cyberland

아직 제출이 없습니다시간 제한7초메모리 제한1024 MB

문제

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 N1N - 1, along with MM bidirectional roads (allowing travel in both directions) indexed from 00 to M1M - 1. The ii-th road (0i<M0 ≤ 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 arr_iarr\_i (0i<N0 ≤ i < N) shows the special abilities of country ii. There are 33 types of special abilities:

  • arr_i=0arr\_i = 0, means this country makes the passing time 00.
  • arr_i=1arr\_i = 1, means the passing time remains unchanged at this country.
  • arr_i=2arr\_i = 2, means this country divides the passing time by 22.

It is guaranteed that arr_0=arr_H=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 to Cyberland, your answer should be 1-1.

제한

  • 2N1052 ≤ N ≤ 10^5, and N105\sum{N} ≤ 10^5.
  • 0Mmin105,N(N1)20 ≤ M ≤ \min{\\{10^5, \frac{N(N-1)}{2}\\}}, and M105\sum{M} ≤ 10^5.
  • 1K1061 ≤ K ≤ 10^6.
  • 1H<N1 ≤ H < N.
  • 0x\[i],y\[i]<N0 ≤ x\[i], y\[i] < N, and x\[i]y\[i]x\[i] \ne y\[i].
  • 1c\[i]1091 ≤ c\[i] ≤ 10^9.
  • arr\[i]0,1,2arr\[i] ∈ \\{0, 1, 2\\}.
  • It is guaranteed that every pair of countries is connected by at most one road.