



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



class 						UpperCAmelCase_					:







       def __init__(     self,    __a):

              '''simple docstring'''

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







       def __lt__(     self,    __a):

              '''simple docstring'''

              return self.key < other.key







       def __repr__(     self):

              '''simple docstring'''

              return self.id







       def      snake_case__   (     self,    __a):

              '''simple docstring'''

              self.neighbors.append(__a)







       def      snake_case__   (     self,    __a,    __a):

              '''simple docstring'''

              _lowerCAmelCase  :							Union[str, Any]				     =					weight






def        A       (      _lowerCamelCase       ,				_lowerCamelCase       ,				_lowerCamelCase       ,				_lowerCamelCase						):





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






def        A       (      _lowerCamelCase       ,				_lowerCamelCase						):





       '''simple docstring'''




       _lowerCAmelCase  :							Union[str, Any]				     =					[]
       for u in graph:
              _lowerCAmelCase  :							List[Any]				     =					math.inf
              _lowerCAmelCase  :							List[str]				     =					None
       _lowerCAmelCase  :							str				     =					0
       _lowerCAmelCase  :							Any				     =					graph[:]
       while q:
              _lowerCAmelCase  :							Any				     =					min(_lowerCamelCase						)
              q.remove(_lowerCamelCase						)
              for v in u.neighbors:
                     if (v in q) and (u.edges[v.id] < v.key):
                            _lowerCAmelCase  :							Union[str, Any]				     =					u
                            _lowerCAmelCase  :							str				     =					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        A       (      _lowerCamelCase       ,				_lowerCamelCase						):





       '''simple docstring'''




       for u in graph:
              _lowerCAmelCase  :							str				     =					math.inf
              _lowerCAmelCase  :							List[str]				     =					None
       _lowerCAmelCase  :							Any				     =					0

       _lowerCAmelCase  :							Any				     =					list(_lowerCamelCase						)
       hq.heapify(_lowerCamelCase						)

       while h:
              _lowerCAmelCase  :							List[Any]				     =					hq.heappop(_lowerCamelCase						)
              for v in u.neighbors:
                     if (v in h) and (u.edges[v.id] < v.key):
                            _lowerCAmelCase  :							str				     =					u
                            _lowerCAmelCase  :							Dict				     =					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        A       (      ):





       '''simple docstring'''










if __name__ == "__main__":
      import doctest

      doctest.testmod()





import baseaa






def        A       (      _lowerCamelCase						):





							'''simple docstring'''




							return baseaa.aaaencode(string.encode("utf-8"						)						)






def        A       (      _lowerCamelCase						):





							'''simple docstring'''




							return baseaa.aaadecode(_lowerCamelCase						).decode("utf-8"						)


if __name__ == "__main__":
						import doctest

						doctest.testmod()
