I take it that you know how to find the shortest path between two nodes of a graph, using breadth-first search or a similar technique. In that method you need to store the lowest cost to each node so far. Instead store both the lowest cost and the lexicographic path, and when two paths have the same cost choose the one with the lower lexicographic path.