= shortest-path distance from s to v

**Theorem 22.5**

G = (V, E) directed or undirected

BFS(G, s), s in V

Upon termination of BFS, every vertex v in V reachable from s has

distance(v) =

For vertex v s reachable from s, one shortest path from s to v
is the shortest path from s to pred(v) followed by edge (pred(v), v)

Print-Path(G, s, v)
; O(V)

if v = s

then print s

else if pred(v) = NIL

then "no path"

else Print-Path(G, s, pred(v))

print v