I thought that if you are given a day to start (which seems to be wrong), it should be easy to apply Dijkstra's algorithm .
It is trivial to create a schedule for the problem. Each node is a city, each of which is a directional edge from one node to another. The weight of the rib is not really determined at all (we cannot just take the trip time) and will be determined during its processing.
So, reduce the problem to a few sub-problems where you know the starting day , as follows:
From a there are k buses to other cities. Thus, bus b i goes from a to b i from the beginning of day i to the end of day i . For each of these tires, create a sub-problem starting at b i at the end of day i (and remember start i ).
To do Dijkstra, considering the starting day and the city:
When studying the schedule, we need to track the current day.
When creating neighbors in city c1 from day d1 for each city c2 where there is a bus from c1 to c2, we generate the earliest bus from c1 to c2 (where you leave from c1> = the current day) (if buses can take different numbers of days, to get from c1 to c2, consider that the earliest arrived at c2). The value of c2 will simply be the number of days from the original start day (beginning i from above) to the day when the bus arrives from c2.
Optimization:
You donโt need to do a full Dijkstra run for each subtask, if you arrived in the city on a specific day, any next subtask that arrives in this city on the same day will have the same path from there, Performing them at the same time will not should be too complex and should lead to increased productivity than to them one at a time.
You can create a heuristic function to be able to use A * .
Feel free to indicate if I missed something.