Add topological sort + acyclic checking for digraph