A recuesive function to perform DFS with vertex i as source
def DFSvisit ( i , mat , visited , sol , n ) : NEW_LINE INDENT visited [ i ] = True NEW_LINE sol . append ( i ) NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( mat [ i ] [ j ] and not visited [ j ] ) : NEW_LINE INDENT DFSvisit ( j , mat , visited , sol , n ) NEW_LINE DEDENT DEDENT DEDENT