Consider a shortest path p from vertex i to vertex j containing at most m edges.
By Lemma 25.1 (subpaths of shortest paths are shortest paths), p' is a shortest path from i to k, and .
Thus, the shortest path problem exhibits optimal substructure.