for dense connected graphs with loops make sure nodes are not visited twice