For example we have the following graph:

number of nodes = 3 (0,1,2)

number of edges = 3

from to cost

0 1 1

0 2 2

1 2 1

Now if we want to go from 0 to 2, there is two shortest path :

- 0 -> 2 . cost = 2
- 0 ->1->2 cost = 2

But 0 -> 1 -> 2 is lexicographically smaller. So this is my answer. For larger inputs how can I always get the correct output?