updating the shortest path algorithm using breath first search