Graph and topological sort