Itexrte through all edges of gxrph , find nodes connecting them . If root nodes of both are same , then there is cycle in gxrph .
for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < adj [ i ] . size ( ) ; j ++ ) {