



"""simple docstring"""







import heapq as hq
import math
from collections.abc import Iterator
class        __A       :







		'''simple docstring'''





		def __init__(	self						:  Dict			,_snake_case						:  Dict						)					->		Tuple:






				"""simple docstring"""



				lowercase__   :    Optional[int]				=			str(id_						)
				lowercase__   :    Tuple				=			None
				lowercase__   :    Dict				=			None
				lowercase__   :    Dict				=			[]
				lowercase__   :    int				=			{}  # {vertex:distance}







		def __lt__(	self						:  List[Any]			,_snake_case						:  int						)					->		Any:






				"""simple docstring"""



				return self.key < other.key







		def __repr__(	self						:  Tuple						)					->		List[str]:






				"""simple docstring"""



				return self.id







		def 					UpperCAmelCase    (	self						:  Dict			,_snake_case						:  Optional[Any]						)					->		Any:






				"""simple docstring"""



				self.neighbors.append(_snake_case						)







		def 					UpperCAmelCase    (	self						:  Tuple			,_snake_case						:  Any			,_snake_case						:  Tuple						)					->		List[str]:






				"""simple docstring"""



				lowercase__   :    Any				=			weight





def      __UpperCAmelCase      (    __lowerCamelCase						,     __lowerCamelCase						,     __lowerCamelCase						,     __lowerCamelCase	)							->      Union[str, Any]:
		# add the neighbors:
		graph[a - 1].add_neighbor(graph[b - 1]	)
		graph[b - 1].add_neighbor(graph[a - 1]	)
		# add the edges:
		graph[a - 1].add_edge(graph[b - 1]						,     __lowerCamelCase	)
		graph[b - 1].add_edge(graph[a - 1]						,     __lowerCamelCase	)



def      __UpperCAmelCase      (    __lowerCamelCase						,     __lowerCamelCase	)							->      list:
		lowercase__   :    List[Any]				=			[]
		for u in graph:
				lowercase__   :    str				=			math.inf
				lowercase__   :    Optional[Any]				=			None
		lowercase__   :    Union[str, Any]				=			0
		lowercase__   :    Tuple				=			graph[:]
		while q:
				lowercase__   :    int				=			min(__lowerCamelCase	)
				q.remove(__lowerCamelCase	)
				for v in u.neighbors:
						if (v in q) and (u.edges[v.id] < v.key):
								lowercase__   :    List[Any]				=			u
								lowercase__   :    Tuple				=			u.edges[v.id]
		for i in range(1						,     len(__lowerCamelCase	)	):
				a.append((int(graph[i].id	) + 1, int(graph[i].pi.id	) + 1)	)
		return a



def      __UpperCAmelCase      (    __lowerCamelCase						,     __lowerCamelCase	)							->      Iterator[tuple]:
		for u in graph:
				lowercase__   :    List[str]				=			math.inf
				lowercase__   :    Any				=			None
		lowercase__   :    Dict				=			0

		lowercase__   :    Any				=			list(__lowerCamelCase	)
		hq.heapify(__lowerCamelCase	)

		while h:
				lowercase__   :    List[str]				=			hq.heappop(__lowerCamelCase	)
				for v in u.neighbors:
						if (v in h) and (u.edges[v.id] < v.key):
								lowercase__   :    str				=			u
								lowercase__   :    Optional[int]				=			u.edges[v.id]
								hq.heapify(__lowerCamelCase	)

		for i in range(1						,     len(__lowerCamelCase	)	):
				yield (int(graph[i].id	) + 1, int(graph[i].pi.id	) + 1)



def      __UpperCAmelCase      (    )							->      None:
		pass


if __name__ == "__main__":
							import doctest

							doctest.testmod()





"""simple docstring"""







from ..utils import DummyObject, requires_backends
class        __A       (	metaclass=A_    ):







		'''simple docstring'''





		lowerCAmelCase			:					List[str]   	=				["torch", "torchsde"]







		def __init__(	self						:  Tuple			,*_snake_case						:  Union[str, Any]			,**_snake_case						:  Any						)					->		Union[str, Any]:






				"""simple docstring"""



				requires_backends(self			,['''torch''', '''torchsde''']						)







		@classmethod
		def 					UpperCAmelCase    (	cls						:  List[str]			,*_snake_case						:  int			,**_snake_case						:  Union[str, Any]						)					->		str:






				"""simple docstring"""



				requires_backends(cls			,['''torch''', '''torchsde''']						)







		@classmethod
		def 					UpperCAmelCase    (	cls						:  List[Any]			,*_snake_case						:  List[Any]			,**_snake_case						:  List[str]						)					->		List[Any]:






				"""simple docstring"""



				requires_backends(cls			,['''torch''', '''torchsde''']						)
