





'''simple docstring'''




from __future__ import annotations

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






@dataclass
class 				__snake_case     :
	__lowerCAmelCase       						=  42
	__lowerCAmelCase       						=  42






class 				__snake_case     :





	def __init__(		self      ,       UpperCamelCase_		)      ->		Optional[Any]:
		snake_case__	       =   [[] for _ in range(UpperCamelCase_		)]
		snake_case__	       =   size





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





	@property
	def   _snake_case   (		self		)      ->		Tuple:
		return self._size





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_		)      ->		Dict:
		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(UpperCamelCase_      ,       UpperCamelCase_		)		)





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_		)      ->		int | None:
		snake_case__	       =   deque([start_vertex]		)
		snake_case__	       =   [None] * self.size
		snake_case__	       =   0

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

			for edge in self[current_vertex]:
				snake_case__	       =   current_distance + edge.weight
				snake_case__	       =   distances[edge.destination_vertex]
				if (
				    isinstance(UpperCamelCase_      ,       UpperCamelCase_		)
				    and new_distance >= dest_vertex_distance
				):
					continue
				snake_case__	       =   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 abc import ABC, abstractmethod
from argparse import ArgumentParser






class 				__snake_case     (					__magic_name__							):





	@staticmethod
	@abstractmethod
	def   _snake_case   (		UpperCamelCase_		)      ->		Dict:
		raise NotImplementedError()





	@abstractmethod
	def   _snake_case   (		self		)      ->		List[Any]:
		raise NotImplementedError()



