





import heapq as hq
import math
from collections.abc import Iterator





class 				a			:






				def __init__(  self			, _lowerCAmelCase					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Dict           =   str(id_					)
										__SCREAMING_SNAKE_CASE:				Dict           =   None
										__SCREAMING_SNAKE_CASE:				Dict           =   None
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   []
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   {}  # {vertex:distance}






				def __lt__(  self			, _lowerCAmelCase					):

										"""simple docstring"""




										return self.key < other.key






				def __repr__(  self					):

										"""simple docstring"""




										return self.id






				def 			snake_case_    (  self			, _lowerCAmelCase					):

										"""simple docstring"""




										self.neighbors.append(_lowerCAmelCase					)






				def 			snake_case_    (  self			, _lowerCAmelCase			, _lowerCAmelCase					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Dict           =   weight






def 		lowerCAmelCase  (	UpperCamelCase__   :   List[Any]       ,			UpperCamelCase__   :   Any       ,			UpperCamelCase__   :   List[str]       ,			UpperCamelCase__   :   List[Any]					)      ->    int:

						"""simple docstring"""





						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]       ,			UpperCamelCase__					)
						graph[b - 1].add_edge(graph[a - 1]       ,			UpperCamelCase__					)






def 		lowerCAmelCase  (	UpperCamelCase__   :   list       ,			UpperCamelCase__   :   Vertex					)      ->    list:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				Dict           =   []
						for u in graph:
												__SCREAMING_SNAKE_CASE:				int           =   math.inf
												__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   None
						__SCREAMING_SNAKE_CASE:				Optional[int]           =   0
						__SCREAMING_SNAKE_CASE:				Optional[int]           =   graph[:]
						while q:
												__SCREAMING_SNAKE_CASE:				str           =   min(UpperCamelCase__					)
												q.remove(UpperCamelCase__					)
												for v in u.neighbors:
																		if (v in q) and (u.edges[v.id] < v.key):
																								__SCREAMING_SNAKE_CASE:				List[str]           =   u
																								__SCREAMING_SNAKE_CASE:				Dict           =   u.edges[v.id]
						for i in range(1       ,			len(UpperCamelCase__					)					):
												a.append((int(graph[i].id					) + 1, int(graph[i].pi.id					) + 1)					)
						return a






def 		lowerCAmelCase  (	UpperCamelCase__   :   list       ,			UpperCamelCase__   :   Vertex					)      ->    Iterator[tuple]:

						"""simple docstring"""





						for u in graph:
												__SCREAMING_SNAKE_CASE:				Optional[int]           =   math.inf
												__SCREAMING_SNAKE_CASE:				Any           =   None
						__SCREAMING_SNAKE_CASE:				Optional[int]           =   0

						__SCREAMING_SNAKE_CASE:				List[str]           =   list(UpperCamelCase__					)
						hq.heapify(UpperCamelCase__					)

						while h:
												__SCREAMING_SNAKE_CASE:				List[Any]           =   hq.heappop(UpperCamelCase__					)
												for v in u.neighbors:
																		if (v in h) and (u.edges[v.id] < v.key):
																								__SCREAMING_SNAKE_CASE:				Dict           =   u
																								__SCREAMING_SNAKE_CASE:				Tuple           =   u.edges[v.id]
																								hq.heapify(UpperCamelCase__					)

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






def 		lowerCAmelCase  (	)      ->    None:

						"""simple docstring"""







if __name__ == "__main__":
							import doctest

							doctest.testmod()










from ..utils import DummyObject, requires_backends





class 				a			(      metaclass=__lowercase			):
				SCREAMING_SNAKE_CASE__     :   List[Any]		      =     ['''torch''', '''scipy''']






				def __init__(  self			, *_lowerCAmelCase			, **_lowerCAmelCase					):

										"""simple docstring"""




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






				@classmethod
				def 			snake_case_    (  cls			, *_lowerCAmelCase			, **_lowerCAmelCase					):

										"""simple docstring"""




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






				@classmethod
				def 			snake_case_    (  cls			, *_lowerCAmelCase			, **_lowerCAmelCase					):

										"""simple docstring"""




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



