is_cyclic_r function

Checks if a graph contains any cycles.