



import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


lowerCAmelCase__		:     Union[str, Any]       						=False
try:
			lowerCAmelCase__		:     Dict       						=_is_package_available('''google.colab''')
except ModuleNotFoundError:
			pass

@input.register
class    UpperCAmelCase_  :

						'''simple docstring'''




						def __init__(    self      ,							_A = None      ,							_A = []		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									=					0
													__SCREAMING_SNAKE_CASE									=					choices
													__SCREAMING_SNAKE_CASE									=					prompt
													if sys.platform == "win32":
																				__SCREAMING_SNAKE_CASE									=					'*'
													else:
																				__SCREAMING_SNAKE_CASE									=					'➔ '






						def        _A	(    self      ,							_A      ,							_A = ""		):







													'''simple docstring'''

													if sys.platform != "win32":
																				writeColor(self.choices[index]      ,							32      ,							_A		)
													else:
																				forceWrite(self.choices[index]      ,							_A		)






						def        _A	(    self      ,							_A		):







													'''simple docstring'''

													if index == self.position:
																				forceWrite(f""" {self.arrow_char} """		)
																				self.write_choice(_A		)
													else:
																				forceWrite(f"""    {self.choices[index]}"""		)
													reset_cursor()






						def        _A	(    self      ,							_A      ,							_A = 1		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									=					self.position
													if direction == Direction.DOWN:
																				if self.position + 1 >= len(self.choices		):
																											return
																				self.position += num_spaces
													else:
																				if self.position - 1 < 0:
																											return
																				self.position -= num_spaces
													clear_line()
													self.print_choice(_A		)
													move_cursor(_A      ,							direction.name		)
													self.print_choice(self.position		)






						@input.mark(KEYMAP['up']		)
						def        _A	(    self		):







													'''simple docstring'''

													self.move_direction(Direction.UP		)






						@input.mark(KEYMAP['down']		)
						def        _A	(    self		):







													'''simple docstring'''

													self.move_direction(Direction.DOWN		)






						@input.mark(KEYMAP['newline']		)
						def        _A	(    self		):







													'''simple docstring'''

													move_cursor(len(self.choices		) - self.position      ,							'DOWN'		)
													return self.position






						@input.mark(KEYMAP['interrupt']		)
						def        _A	(    self		):







													'''simple docstring'''

													move_cursor(len(self.choices		) - self.position      ,							'DOWN'		)
													raise KeyboardInterrupt






						@input.mark_multiple(*[KEYMAP[str(_A		)] for number in range(10		)]		)
						def        _A	(    self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									=					int(chr(self.current_selection		)		)
													__SCREAMING_SNAKE_CASE									=					index - self.position
													if index == self.position:
																				return
													if index < len(self.choices		):
																				if self.position > index:
																											self.move_direction(Direction.UP      ,							-movement		)
																				elif self.position < index:
																											self.move_direction(Direction.DOWN      ,							_A		)
																				else:
																											return
													else:
																				return






						def        _A	(    self      ,							_A = 0		):







													'''simple docstring'''

													if self.prompt:
																				linebreak()
																				forceWrite(self.prompt      ,							'\n'		)
																				if in_colab:
																											forceWrite('Please input a choice index (starting from 0), and press enter'      ,							'\n'		)
																				else:
																											forceWrite('Please select a choice using the arrow or number keys, and selecting with enter'      ,							'\n'		)
													__SCREAMING_SNAKE_CASE									=					default_choice
													for i in range(len(self.choices		)		):
																				self.print_choice(_A		)
																				forceWrite('\n'		)
													move_cursor(len(self.choices		) - self.position      ,							'UP'		)
													with cursor.hide():
																				while True:
																											if in_colab:
																																		try:
																																									__SCREAMING_SNAKE_CASE									=					int(builtins.input()		)
																																		except ValueError:
																																									__SCREAMING_SNAKE_CASE									=					default_choice
																											else:
																																		__SCREAMING_SNAKE_CASE									=					self.handle_input()
																											if choice is not None:
																																		reset_cursor()
																																		for _ in range(len(self.choices		) + 1		):
																																									move_cursor(1      ,							'UP'		)
																																									clear_line()
																																		self.write_choice(_A      ,							'\n'		)
																																		return choice








from collections import defaultdict

from graphs.minimum_spanning_tree_prims import prisms_algorithm as mst





def 			lowerCamelCase_ (				):
				lowerCamelCase_	,    lowerCamelCase_						=			9, 1_4  # noqa: F841
				lowerCamelCase_						=			[
				    [0, 1, 4],
				    [0, 7, 8],
				    [1, 2, 8],
				    [7, 8, 7],
				    [7, 6, 1],
				    [2, 8, 2],
				    [8, 6, 6],
				    [2, 3, 7],
				    [2, 5, 4],
				    [6, 5, 2],
				    [3, 5, 1_4],
				    [3, 4, 9],
				    [5, 4, 1_0],
				    [1, 7, 1_1],
				]

				lowerCamelCase_						=			defaultdict(lowerCamelCase__    )
				for nodea, nodea, cost in edges:
								adjancency[nodea].append([nodea, cost]    )
								adjancency[nodea].append([nodea, cost]    )

				lowerCamelCase_						=			mst(lowerCamelCase__    )

				lowerCamelCase_						=			[
				    [7, 6, 1],
				    [2, 8, 2],
				    [6, 5, 2],
				    [0, 1, 4],
				    [2, 5, 4],
				    [2, 3, 7],
				    [0, 7, 8],
				    [3, 4, 9],
				]

				for answer in expected:
								lowerCamelCase_						=			tuple(answer[:2]    )
								lowerCamelCase_						=			tuple(edge[::-1]    )
								assert edge in result or reverse in result


