Add topological sort.