


from __future__ import annotations




def   snake_case		(     UpperCamelCase__       :						list[list[int]]    )   ->      bool:
      lowerCamelCase					:					Dict        =	len(UpperCamelCase__    )
      # We need to create solution object to save path.
      lowerCamelCase					:					Any        =	[[0 for _ in range(UpperCamelCase__    )] for _ in range(UpperCamelCase__    )]
      lowerCamelCase					:					Dict        =	run_maze(UpperCamelCase__			,				0			,				0			,				UpperCamelCase__    )
      if solved:
            print("""\n""".join(str(UpperCamelCase__    ) for row in solutions    )    )
      else:
            print("""No solution exists!"""    )
      return solved




def   snake_case		(     UpperCamelCase__       :						list[list[int]]			,				UpperCamelCase__       :						int			,				UpperCamelCase__       :						int			,				UpperCamelCase__       :						list[list[int]]    )   ->      bool:
      lowerCamelCase					:					Any        =	len(UpperCamelCase__    )
      # Final check point.
      if i == j == (size - 1):
            lowerCamelCase					:					int        =	1
            return True

      lowerCamelCase					:					int        =	(not i < 0) and (not j < 0)  # Check lower bounds
      lowerCamelCase					:					Optional[int]        =	(i < size) and (j < size)  # Check upper bounds

      if lower_flag and upper_flag:
            # check for already visited and block points.
            lowerCamelCase					:					List[Any]        =	(not solutions[i][j]) and (not maze[i][j])
            if block_flag:
                  # check visited
                  lowerCamelCase					:					str        =	1

                  # check for directions
                  if (
                      run_maze(UpperCamelCase__			,				i + 1			,				UpperCamelCase__			,				UpperCamelCase__    )
                      or run_maze(UpperCamelCase__			,				UpperCamelCase__			,				j + 1			,				UpperCamelCase__    )
                      or run_maze(UpperCamelCase__			,				i - 1			,				UpperCamelCase__			,				UpperCamelCase__    )
                      or run_maze(UpperCamelCase__			,				UpperCamelCase__			,				j - 1			,				UpperCamelCase__    )
                  ):
                        return True

                  lowerCamelCase					:					Optional[int]        =	0
                  return False
      return False


if __name__ == "__main__":
    import doctest

    doctest.testmod()








"""simple docstring"""


__lowerCamelCase      :List[Any]	    =		{0: [2, 3], 1: [0], 2: [1], 3: [4], 4: []}

__lowerCamelCase      :Union[str, Any]	    =		{0: [1, 2, 3], 1: [2], 2: [0], 3: [4], 4: [5], 5: [3]}




def   snake_case		(     UpperCamelCase__       :						dict[int, list[int]]			,				UpperCamelCase__       :						int			,				UpperCamelCase__       :						list[bool]    )   ->      list[int]:
      lowerCamelCase					:					Tuple        =	True
      lowerCamelCase					:					Any        =	[]

      for neighbour in graph[vert]:
            if not visited[neighbour]:
                  order += topology_sort(UpperCamelCase__			,				UpperCamelCase__			,				UpperCamelCase__    )

      order.append(UpperCamelCase__    )

      return order




def   snake_case		(     UpperCamelCase__       :						dict[int, list[int]]			,				UpperCamelCase__       :						int			,				UpperCamelCase__       :						list[bool]    )   ->      list[int]:
      lowerCamelCase					:					List[Any]        =	True
      lowerCamelCase					:					int        =	[vert]

      for neighbour in reversed_graph[vert]:
            if not visited[neighbour]:
                  component += find_components(UpperCamelCase__			,				UpperCamelCase__			,				UpperCamelCase__    )

      return component






def   snake_case		(     UpperCamelCase__       :						dict[int, list[int]]    )   ->      list[list[int]]:
      lowerCamelCase					:					int        =	len(UpperCamelCase__    ) * [False]
      lowerCamelCase					:					dict[int, list[int]]        =	{vert: [] for vert in range(len(UpperCamelCase__    )    )}

      for vert, neighbours in graph.items():
            for neighbour in neighbours:
                  reversed_graph[neighbour].append(UpperCamelCase__    )

      lowerCamelCase					:					int        =	[]
      for i, was_visited in enumerate(UpperCamelCase__    ):
            if not was_visited:
                  order += topology_sort(UpperCamelCase__			,				UpperCamelCase__			,				UpperCamelCase__    )

      lowerCamelCase					:					Tuple        =	[]
      lowerCamelCase					:					str        =	len(UpperCamelCase__    ) * [False]

      for i in range(len(UpperCamelCase__    )    ):
            lowerCamelCase					:					Any        =	order[len(UpperCamelCase__    ) - i - 1]
            if not visited[vert]:
                  lowerCamelCase					:					List[str]        =	find_components(UpperCamelCase__			,				UpperCamelCase__			,				UpperCamelCase__    )
                  components_list.append(UpperCamelCase__    )

      return components_list




