Itexrte through all edges of gxrph , find nodes connecting them . If root nodes of both are same , then there is cycle in gxrph .
for i in range ( V ) : NEW_LINE INDENT for j in range ( len ( adj [ i ] ) ) : NEW_LINE DEDENT