I couldn’t see where you enforce that destination of city 1 is always achieved at time zero, whatever trains are available, in fact even with no trains.
I have made one[] array to store the distance if 1 comes. similarly with two[] array. Can you provide some test cases that is not working. It would be great.