


"""simple docstring"""







def  a__      (    SCREAMING_SNAKE_CASE   :   list[list[int]]    ,				SCREAMING_SNAKE_CASE   :   int    ,				SCREAMING_SNAKE_CASE   :   int    ,				SCREAMING_SNAKE_CASE   :   list[int]    ):


  '''simple docstring'''







  if graph[path[curr_ind - 1]][next_ver] == 0:
    return False

  # 2. Validate that next vertex is not already in path
  return not any(vertex == next_ver for vertex in path    )
def  a__      (    SCREAMING_SNAKE_CASE   :   list[list[int]]    ,				SCREAMING_SNAKE_CASE   :   list[int]    ,				SCREAMING_SNAKE_CASE   :   int    ):


  '''simple docstring'''







  if curr_ind == len(SCREAMING_SNAKE_CASE    ):
    # return whether path exists between current and starting vertices
    return graph[path[curr_ind - 1]][path[0]] == 1

  # Recursive Step
  for next_ver in range(0    ,				len(SCREAMING_SNAKE_CASE    )    ):
    if valid_connection(SCREAMING_SNAKE_CASE    ,				SCREAMING_SNAKE_CASE    ,				SCREAMING_SNAKE_CASE    ,				SCREAMING_SNAKE_CASE    ):
      # Insert current vertex  into path as next transition
      lowerCAmelCase					:					str								=							next_ver
      # Validate created path
      if util_hamilton_cycle(SCREAMING_SNAKE_CASE    ,				SCREAMING_SNAKE_CASE    ,				curr_ind + 1    ):
        return True
      # Backtrack
      lowerCAmelCase					:					Tuple								=							-1
  return False





def  a__      (    SCREAMING_SNAKE_CASE   :   list[list[int]]    ,				SCREAMING_SNAKE_CASE   :   int = 0    ):


  '''simple docstring'''







  lowerCAmelCase					:					Optional[int]								=							[-1] * (len(SCREAMING_SNAKE_CASE    ) + 1)
  # initialize start and end of path with starting index
  lowerCAmelCase					:					List[str]								=							start_index
  # evaluate and if we find answer return path either return empty array
  return path if util_hamilton_cycle(SCREAMING_SNAKE_CASE    ,				SCREAMING_SNAKE_CASE    ,				1    ) else []









"""simple docstring"""







from typing import Any


class 				SCREAMING_SNAKE_CASE__    :
       """simple docstring"""


       def __init__(						self		,					snake_case__						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[Any]								=							data
         lowerCAmelCase					:					Tuple								=							None


class 				SCREAMING_SNAKE_CASE__    :
       """simple docstring"""


       def __init__(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[int]								=							None

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[Any]								=							self.head
         while temp is not None:
           print(temp.data		,					end=" "						)
           lowerCAmelCase					:					List[str]								=							temp.next
         print()

       def 	lowercase__							(						self		,					snake_case__						):






         """simple docstring"""





         lowerCAmelCase					:					int								=							Node(snake_case__						)
         lowerCAmelCase					:					Union[str, Any]								=							self.head
         lowerCAmelCase					:					Optional[Any]								=							new_node







       def 	lowercase__							(						self		,					snake_case__		,					snake_case__						):






         """simple docstring"""





         if node_data_a == node_data_a:
           return
         else:
           lowerCAmelCase					:					str								=							self.head
           while node_a is not None and node_a.data != node_data_a:
             lowerCAmelCase					:					Union[str, Any]								=							node_a.next

           lowerCAmelCase					:					Any								=							self.head
           while node_a is not None and node_a.data != node_data_a:
             lowerCAmelCase					:					List[Any]								=							node_a.next

           if node_a is None or node_a is None:
             return

           lowerCAmelCase						,  lowerCAmelCase					:					str								=							node_a.data, node_a.data


if __name__ == "__main__":
     lowerCAmelCase__				    =       LinkedList()
     for i in range(5, 0, -1):
          ll.push(i)

     ll.print_list()

     ll.swap_nodes(1, 4)
     print('''After swapping''')
     ll.print_list()





