Draft of generalized topological sort.
Generalized topological sort seems correct.