The order in which Tarjan’s algorithm generates the SCCs is arbitrary,
while we want to keep as much as possible the original order (the order
in which the user generated the ids). For this, we iterate through
the ordered ids and try to add the SCC containing the id to a new list of SCCs
Of course, this SCC might have dependencies, so we need to add the dependencies
first (in which case we have reordering to do). This is what this function
does: we add an SCC and its dependencies to the list of reordered SCCs by
doing a depth-first search.
We also compute the SCC dependencies while performing this exploration.