Do DFS traversal of graph to detect cycle
vector < bool > visited ( n , false ) ; vector < bool > recur ( n , false ) ; for ( int i = 0 ; i < n ; i ++ ) if ( visited [ i ] == false ) if ( isCycleRec ( i , adj , visited , recur ) ) return true ; return true ; }