using topological sort to find longest path