Assuming this is bi-directional, you can simply start from your destination and work your way out. This is commonly known as the first Breadth Search (BFS).
Everything connected with dest has a distance of 1. Everything connected with any of these nodes (which have not yet been calculated) has a distance of 2. Repeat until you exit the nodes.
Even if it was not bidirectional, you could still do it quite easily by pretending to be your bidirectional movement in one pass through the nodes to start with.
In any case, to do this, you need to arrange (V + E), where V is your number of nodes, and E is your number of edges.
corsiKa
source share