Since i am new to programming with python language, i am seeking for your help.
The problem is as follows:
I have an input of 5 integers: 1st the number of cities 2nd the number of roads 3rd the number of K (smaller than the 1st) of cities where a race will take place 4rd the number of required refuels 5th the number of gas stations
Then an input that describes which cities are connected and the distance, for example, 1 2 4 presents that city 1 connects with city 2 and the road has a distance 4. This for all roads.
An input presenting the number of cities that the race is taking over, for example if the total cities are 5 (C1,C2,C3,C4,C5) and this input is 1 2 4 5 this means that the race will be at the cities C1, C2, C4, C5.
and finally a set of integers indicating at which cities there is a gas station.
An example of the input is 58421 124 131 142 243 345 512 531 523 1 2 4 3 5
The goal here is to race in all the given cities and stop at a gas station (based on the input, at a city that has a gas station) and where I stop for gas, my team comes from the nearest city and adds this time to my racing time. What is an optimal algorithm for this problem?
I tried BFS but I cannot implement the inputs in the code.