
from __future__ import annotations

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

@dataclass
class    lowerCAmelCase__     :
		a__       :						int
		a__       :						int





class    lowerCAmelCase__     :






		def __init__(		self		:							Optional[int]							,			SCREAMING_SNAKE_CASE__		:							int  )     ->							Union[str, Any]:
						__lowerCamelCase    					=	[[] for _ in range(SCREAMING_SNAKE_CASE__  )]
						__lowerCamelCase    					=	size






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






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






		def  __A       (		self		:							Union[str, Any]							,			SCREAMING_SNAKE_CASE__		:							int							,			SCREAMING_SNAKE_CASE__		:							int							,			SCREAMING_SNAKE_CASE__		:							int  )     ->							int:
						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(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  )  )







		def  __A       (		self		:							Union[str, Any]							,			SCREAMING_SNAKE_CASE__		:							int							,			SCREAMING_SNAKE_CASE__		:							int  )     ->							int | None:
						__lowerCamelCase    					=	deque([start_vertex]  )
						__lowerCamelCase    					=	[None] * self.size
						__lowerCamelCase    					=	0

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

										for edge in self[current_vertex]:
														__lowerCamelCase    					=	current_distance + edge.weight
														__lowerCamelCase    					=	distances[edge.destination_vertex]
														if (
														    isinstance(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  )
														    and new_distance >= dest_vertex_distance
														):
																		continue
														__lowerCamelCase    					=	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()





from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
					if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0")):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from ...utils.dummy_torch_and_transformers_objects import UnCLIPImageVariationPipeline, UnCLIPPipeline
else:
					from .pipeline_unclip import UnCLIPPipeline
					from .pipeline_unclip_image_variation import UnCLIPImageVariationPipeline
					from .text_proj import UnCLIPTextProjModel



