Detect a Cycle in a Graph