Added cycle detection cpp