





"""simple docstring"""





from __future__ import annotations

from collections import deque
from collections.abc import Iterator
from dataclasses import dataclass





@dataclass
class        _lowerCamelCase      :
						UpperCAmelCase_ =			42
						UpperCAmelCase_ =			42





class        _lowerCamelCase      :


						def __init__(self   ,							__a		) ->   List[Any]:
								UpperCamelCase   =	[[] for _ in range(__a		)]
								UpperCamelCase   =	size


						def __getitem__(self   ,							__a		) ->   Iterator[Edge]:
								return iter(self._graph[vertex]		)


						@property
						def     snake_case_   (self		) ->   str:
								return self._size


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a		) ->   List[Any]:
								if weight not in (0, 1):
										raise ValueError("Edge weight must be either 0 or 1."		)

								if to_vertex < 0 or to_vertex >= self.size:
										raise ValueError("Vertex indexes must be in [0; size)."		)

								self._graph[from_vertex].append(Edge(__a   ,							__a		)		)




						def     snake_case_   (self   ,							__a   ,							__a		) ->   int | None:
								UpperCamelCase   =	deque([start_vertex]		)
								UpperCamelCase   =	[None] * self.size
								UpperCamelCase   =	0

								while queue:
										UpperCamelCase   =	queue.popleft()
										UpperCamelCase   =	distances[current_vertex]
										if current_distance is None:
												continue

										for edge in self[current_vertex]:
												UpperCamelCase   =	current_distance + edge.weight
												UpperCamelCase   =	distances[edge.destination_vertex]
												if (
												    isinstance(__a   ,							__a		)
												    and new_distance >= dest_vertex_distance
												):
														continue
												UpperCamelCase   =	new_distance
												if edge.weight == 0:
														queue.appendleft(edge.destination_vertex		)
												else:
														queue.append(edge.destination_vertex		)

								if distances[finish_vertex] is None:
										raise ValueError("No path from start_vertex to finish_vertex."		)

								return distances[finish_vertex]


if __name__ == "__main__":
						import doctest

						doctest.testmod()













"""simple docstring"""





from typing import List

from .keymap import KEYMAP, get_character


def       a__					(					_SCREAMING_SNAKE_CASE    ):




		"""simple docstring"""


		def decorator(_SCREAMING_SNAKE_CASE    ):
				UpperCamelCase   =	getattr(_SCREAMING_SNAKE_CASE  ,	"handle_key"  ,	[]    )
				handle += [key]
				setattr(_SCREAMING_SNAKE_CASE  ,	"handle_key"  ,	_SCREAMING_SNAKE_CASE    )
				return func

		return decorator


def       a__					(					*_SCREAMING_SNAKE_CASE    ):




		"""simple docstring"""


		def decorator(_SCREAMING_SNAKE_CASE    ):
				UpperCamelCase   =	getattr(_SCREAMING_SNAKE_CASE  ,	"handle_key"  ,	[]    )
				handle += keys
				setattr(_SCREAMING_SNAKE_CASE  ,	"handle_key"  ,	_SCREAMING_SNAKE_CASE    )
				return func

		return decorator





class        _lowerCamelCase      (       _lowercase ):


						def __new__(cls   ,							__a   ,							__a   ,							__a		) ->   Any:
								UpperCamelCase   =	super().__new__(cls   ,							__a   ,							__a   ,							__a		)
								if not hasattr(__a   ,							"key_handler"		):
										setattr(__a   ,							"key_handler"   ,							{}		)
								setattr(__a   ,							"handle_input"   ,							KeyHandler.handle_input		)

								for value in attrs.values():
										UpperCamelCase   =	getattr(__a   ,							"handle_key"   ,							[]		)
										for key in handled_keys:
												UpperCamelCase   =	value
								return new_cls




						@staticmethod
						def     snake_case_   (cls		) ->   Optional[Any]:
								UpperCamelCase   =	get_character()
								if char != KEYMAP["undefined"]:
										UpperCamelCase   =	ord(__a		)
								UpperCamelCase   =	cls.key_handler.get(__a		)
								if handler:
										UpperCamelCase   =	char
										return handler(cls		)
								else:
										return None



def       a__					(					cls    ):




		"""simple docstring"""


		return KeyHandler(cls.__name__  ,	cls.__bases__  ,	cls.__dict__.copy()    )






