Depth First Search with topological Sort.