DAG topological sort