Cyberland
Time limit7sMemory limit1024 MB
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 countries indexed from to , along with bidirectional roads (allowing travel in both directions) indexed from to . The -th road () connects two different countries, and , and requires a certain amount of time to pass the road. All participants have gathered in Cyberland for the APIO, except for your country. You are living in country , and Cyberland is country . 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 (divide-by- 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- ability at most 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 is given, where () shows the special abilities of country . There are types of special abilities: means this country makes the passing time . means the passing time remains unchanged at this country. means this country divides the passing time by . It is guaranteed that 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 .
Constraints
, and . , and . . . , and . . . It is guaranteed that every pair of countries is connected by at most one road.