The program now exits directly after finding a cycle.