Magic Potion
Time limit2sMemory limit512 MB
Given a complete graph with edge weights and K potions that halve one trip's time, find the shortest time from city 0 to city 1.
- Level
Medium5 of 10
- Topics
- Shortest path, Graph, Dynamic programming
- Solved
- No attempts yet
Problem
There are cities numbered 0 to . Every pair of cities is directly connected, so travel between any two cities is always possible.
You are given the travel time between every pair of cities and the number of magic potions that you hold. Drinking a magic potion lets you move twice as fast as usual. When you travel from one city to another you may use one magic potion, and that trip then takes half its usual time. You cannot spend two or more potions on a single trip, and you do not have to drink every potion you hold.
Find the shortest time to get from city 0 to city 1.
Input
The first line contains the number of cities and the number of magic potions . (, )
The next lines contain the travel time matrix. Each line is digits written with no separators. The value in row , column is the time to travel from city to city , and rows and columns are both counted from 0. Each time is an integer between 0 and 9.
For all and , the value in row , column equals the value in row , column , and the value in row , column is always 0.
Output
Print the shortest time from city 0 to city 1 with exactly one digit after the decimal point. The answer is always a multiple of 0.5, so one decimal digit represents it exactly.