Use a set of visited nodes to find backedges