The key here was to pre-calculate all shortest paths starting from the goal