In Python 3, using sys.stdin, please.
Using a Dijkstra Priority First Search algorithm.
Optimization 20 marks
Suppose you decided to travel around NZ in your new electric car. The car can travel exactly 100 kms once the battery is fully charged. Recharging is only possible at towns, and you have taken note of all these locations prior to your departure. Your aim is to find the length of the shortest possible path from an origin town to a destination town, given the range restriction of your car. The landscape is an n x n square (units are km) with coordinates for towns described by (2y), where 0 < x, y < n. Use Euclidean distance to calculate the distance between towns.
Input format: The input is taken from the keyboard (e.g. by sys.stdin) as multiple lines of comma-separated integers. Each line has 2p + numbers, where p > 2. The first number on each line is the size of the landscape. The following 2p numbers give locations of p towns, so the jth town with the recharging station is at (2j, 2j + 1). The first position listed on each line is the origin, and the final position listed is the destination.
For example:
100, 0, 0, 0, 100, 100, 100
1000, 20, 892, 986, 602, 138
0.97, 206.2, 10.44
200, 25, 25, 10, 1, 50, 25, 140, 30
Output format: For each line of input, output a single number to the console, which is the length of the shortest path from the origin to the destination. Use str format to give this value to 2 decimal places precisely. Format using {:.2f}. Do not use any other rounding throughout your algorithm. If the destination town is unreachable from the origin, output -1.
200.00
115.14