Depth-first search, line by line
A recursive depth-first search on an adjacency matrix, one step at a time, with the call stack and the parent map.
The order in which vertices are entered is the sequence S. The parent map has the same vertices as keys, but a dictionary does not record order.