Find if possible to visit every nodes in given Graph exactly once based on given conditions | Function to find print path ; If a [ 0 ] is 1 ; Printing path ; Seeking for a [ i ] = 0 and a [ i + 1 ] = 1 ; Printing path ; If a [ N - 1 ] = 0 ; Driver Code ; Given Input ; Function Call
def findpath ( N , a ) : NEW_LINE INDENT if ( a [ 0 ] ) : NEW_LINE INDENT print ( N + 1 ) NEW_LINE for i in range ( 1 , N + 1 , 1 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT return NEW_LINE DEDENT for i in range ( N - 1 ) : NEW_LINE INDENT if ( a [ i ] == 0 and a [ i + 1 ] ) : NEW_LINE INDENT for j in range ( 1 , i + 1 , 1 ) : NEW_LINE INDENT print ( j , end = " ▁ " ) NEW_LINE DEDENT print ( N + 1 , end = " ▁ " ) ; NEW_LINE for j in range ( i + 1 , N + 1 , 1 ) : NEW_LINE INDENT print ( j , end = " ▁ " ) NEW_LINE DEDENT return NEW_LINE DEDENT DEDENT for i in range ( 1 , N + 1 , 1 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT print ( N + 1 , end = " ▁ " ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 NEW_LINE arr = [ 0 , 1 , 0 ] NEW_LINE findpath ( N , arr ) NEW_LINE DEDENT