Type the topological-sort emit step (append on finish, reverse at the end)
Type the topological-sort emit step (append on finish, reverse at the end)
Answer
color[u] = BLACK result.append(u) # finished # ... after all DFS: result.reverse() # decreasing finish time
Appending on finish then reversing is equivalent to pushing onto the front of a list. The result is vertices in decreasing finish time = a valid topological order.