Topological sort here is nonstandard. It may decide to skip some nodes (line 722 below). It tolerates some cycles (lines 749 and 750). It also modifies the implicit graph on the fly (lines 743 and 744) in a nonstandard step compared to Goldberg and Radzik's paper. To have a topological sort implementation that allows all these customizations is tricky.