In this problem you are going to find the path that has minimal weight and is lexicographically smallest.
You may construct such solution from backward, in a dynamic programming fashion. A reference solution is here