One day, Koraidon gave Miraidon a
directed graph with
nnn vertices and
mmm edges. The weights of all edges are
111. Koraidon asked Miraidon to calculate the shortest path from vertex
111 to each vertex. It is guaranteed that vertex
111 can reach all other vertices through the edges.
However, Miraidon just forgot the BFS algorithm. He tried to use the DFS algorithm as a replacement. The algorithm looks like:
In line
444, Miraidon tried to use a random shuffle function to get a correct answer. The shuffles in different recursive calls of DFS are mutually independent.
Koraidon judged the answer given by Miraidon very strictly. He would consider the algorithm correct if and only if the algorithm gives correct answers on all possible random shuffle results.
Please help Miraidon check whether his DFS algorithm is correct on the given graph.