






"""simple docstring"""
from __future__ import annotations






def 			__UpperCamelCase	(		snake_case__					):
	A_		:						int	    =   len(snake_case__					)
	# We need to create solution object to save path.
	A_		:						Optional[Any]	    =   [[0 for _ in range(snake_case__					)] for _ in range(snake_case__					)]
	A_		:						List[str]	    =   run_maze(snake_case__   ,   0   ,   0   ,   snake_case__					)
	if solved:
		print("""\n""".join(str(snake_case__					) for row in solutions					)					)
	else:
		print("""No solution exists!"""					)
	return solved






def 			__UpperCamelCase	(		snake_case__   ,   snake_case__   ,   snake_case__   ,   snake_case__					):
	A_		:						List[str]	    =   len(snake_case__					)
	# Final check point.
	if i == j == (size - 1):
		A_		:						List[Any]	    =   1
		return True

	A_		:						List[str]	    =   (not i < 0) and (not j < 0)  # Check lower bounds
	A_		:						int	    =   (i < size) and (j < size)  # Check upper bounds

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

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

			A_		:						Tuple	    =   0
			return False
	return False


if __name__ == "__main__":
	import doctest

	doctest.testmod()









"""simple docstring"""
def 			__UpperCamelCase	(		snake_case__   ,   snake_case__   ,   snake_case__					):
	return not any(
	    neighbour == 1 and colored_vertices[i] == color
	    for i, neighbour in enumerate(snake_case__					)					)






def 			__UpperCamelCase	(		snake_case__   ,   snake_case__   ,   snake_case__   ,   snake_case__					):

	# Base Case
	if index == len(snake_case__					):
		return True

	# Recursive Step
	for i in range(snake_case__					):
		if valid_coloring(graph[index]   ,   snake_case__   ,   snake_case__					):
			# Color current vertex
			A_		:						Dict	    =   i
			# Validate coloring
			if util_color(snake_case__   ,   snake_case__   ,   snake_case__   ,   index + 1					):
				return True
			# Backtrack
			A_		:						Union[str, Any]	    =   -1
	return False






def 			__UpperCamelCase	(		snake_case__   ,   snake_case__					):
	A_		:						int	    =   [-1] * len(snake_case__					)

	if util_color(snake_case__   ,   snake_case__   ,   snake_case__   ,   0					):
		return colored_vertices

	return []

