




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





class 	lowerCamelCase_							:


	'''simple docstring'''







	def __init__(							self  :		Dict    ,    _lowerCAmelCase  :		str						):
							SCREAMING_SNAKE_CASE_     						=      str(id_						)
							SCREAMING_SNAKE_CASE_     						=      None
							SCREAMING_SNAKE_CASE_     						=      None
							SCREAMING_SNAKE_CASE_     						=      []
							SCREAMING_SNAKE_CASE_     						=      {}  # {vertex:distance}



	def __lt__(							self  :		List[Any]    ,    _lowerCAmelCase  :		Union[str, Any]						):
							return self.key < other.key



	def __repr__(							self  :		str						):
							return self.id



	def 				lowerCAmelCase_  (							self  :		Optional[int]    ,    _lowerCAmelCase  :		Dict						):
							self.neighbors.append(_lowerCAmelCase						)




	def 				lowerCAmelCase_  (							self  :		Tuple    ,    _lowerCAmelCase  :		List[Any]    ,    _lowerCAmelCase  :		Tuple						):
							SCREAMING_SNAKE_CASE_     						=      weight


def  UpperCAmelCase_							(				__UpperCAmelCase						:     Union[str, Any]      ,      __UpperCAmelCase						:     Optional[Any]      ,      __UpperCAmelCase						:     Optional[int]      ,      __UpperCAmelCase						:     Dict							) ->			Dict:
						# 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]      ,      __UpperCAmelCase							)
						graph[b - 1].add_edge(graph[a - 1]      ,      __UpperCAmelCase							)

def  UpperCAmelCase_							(				__UpperCAmelCase						:     list      ,      __UpperCAmelCase						:     Vertex							) ->			list:
						SCREAMING_SNAKE_CASE_     						=      []
						for u in graph:
												SCREAMING_SNAKE_CASE_     						=      math.inf
												SCREAMING_SNAKE_CASE_     						=      None
						SCREAMING_SNAKE_CASE_     						=      0
						SCREAMING_SNAKE_CASE_     						=      graph[:]
						while q:
												SCREAMING_SNAKE_CASE_     						=      min(__UpperCAmelCase							)
												q.remove(__UpperCAmelCase							)
												for v in u.neighbors:
																		if (v in q) and (u.edges[v.id] < v.key):
																								SCREAMING_SNAKE_CASE_     						=      u
																								SCREAMING_SNAKE_CASE_     						=      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  UpperCAmelCase_							(				__UpperCAmelCase						:     list      ,      __UpperCAmelCase						:     Vertex							) ->			Iterator[tuple]:
						for u in graph:
												SCREAMING_SNAKE_CASE_     						=      math.inf
												SCREAMING_SNAKE_CASE_     						=      None
						SCREAMING_SNAKE_CASE_     						=      0

						SCREAMING_SNAKE_CASE_     						=      list(__UpperCAmelCase							)
						hq.heapify(__UpperCAmelCase							)

						while h:
												SCREAMING_SNAKE_CASE_     						=      hq.heappop(__UpperCAmelCase							)
												for v in u.neighbors:
																		if (v in h) and (u.edges[v.id] < v.key):
																								SCREAMING_SNAKE_CASE_     						=      u
																								SCREAMING_SNAKE_CASE_     						=      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  UpperCAmelCase_							(				) ->			None:
						pass


if __name__ == "__main__":
			import doctest

			doctest.testmod()





from abc import ABC, abstractmethod
from argparse import ArgumentParser





class 	lowerCamelCase_							(				_SCREAMING_SNAKE_CASE ):


 '''simple docstring'''







 @staticmethod
 @abstractmethod
 def 				lowerCAmelCase_  (							_lowerCAmelCase  :		ArgumentParser						):
       raise NotImplementedError()




 @abstractmethod
 def 				lowerCAmelCase_  (							self  :		Dict						):
       raise NotImplementedError()