Function checks if a cell is valid , i . e . it is inside the grid and equal to 1
def is_valid ( x , y , matrix ) : NEW_LINE INDENT if ( x < n and y < m and x >= 0 and y >= 0 ) : NEW_LINE INDENT if ( visited [ x ] [ y ] == False and matrix [ x ] [ y ] == 1 ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT