We want to modify our Bellman-Ford algorithm to return not only the array of distances but also the paths themselves. As we mentioned, this can be achieved using backtracking: if relaxation along the edge is successful, store the index in an array . Denote .
What will be the time complexity of our algorithm after the modification?