





'''simple docstring'''

class lowerCamelCase						:







  def __init__(		self		)		->						Tuple:






        """simple docstring"""





        _snake_case		:	Union[str, Any]					     =     0
        _snake_case		:	Any					     =     0
        _snake_case		:	int					     =     {}







  def 				UpperCAmelCase_				(		self     ,     lowercase__		)		->						Tuple:






        """simple docstring"""





        if vertex not in self.adjacency:
              _snake_case		:	Tuple					     =     {}
              self.num_vertices += 1







  def 				UpperCAmelCase_				(		self     ,     lowercase__     ,     lowercase__     ,     lowercase__		)		->						List[Any]:






        """simple docstring"""





        self.add_vertex(UpperCAmelCase_		)
        self.add_vertex(UpperCAmelCase_		)

        if head == tail:
              return

        _snake_case		:	Tuple					     =     weight
        _snake_case		:	Optional[int]					     =     weight







  def 				UpperCAmelCase_				(		self		)		->						str:






        """simple docstring"""





        _snake_case		:	List[Any]					     =     self.get_edges()
        for edge in edges:
              _snake_case		:	str					     =     edge
              edges.remove((tail, head, weight)		)
        for i in range(len(UpperCAmelCase_		)		):
              _snake_case		:	Any					     =     list(edges[i]		)

        edges.sort(key=lambda lowercase__		: e[2]		)
        for i in range(len(UpperCAmelCase_		) - 1		):
              if edges[i][2] >= edges[i + 1][2]:
                    _snake_case		:	Optional[int]					     =     edges[i][2] + 1
        for edge in edges:
              _snake_case		:	List[Any]					     =     edge
              _snake_case		:	Dict					     =     weight
              _snake_case		:	List[Any]					     =     weight







  def __str__(		self		)		->						List[str]:






        """simple docstring"""





        _snake_case		:	List[Any]					     =     ''
        for tail in self.adjacency:
              for head in self.adjacency[tail]:
                    _snake_case		:	Union[str, Any]					     =     self.adjacency[head][tail]
                    string += F'''{head} -> {tail} == {weight}\n'''
        return string.rstrip('''\n'''		)







  def 				UpperCAmelCase_				(		self		)		->						Dict:






        """simple docstring"""





        _snake_case		:	Optional[Any]					     =     []
        for tail in self.adjacency:
              for head in self.adjacency[tail]:
                    output.append((tail, head, self.adjacency[head][tail])		)
        return output







  def 				UpperCAmelCase_				(		self		)		->						int:






        """simple docstring"""





        return self.adjacency.keys()







  @staticmethod
  def 				UpperCAmelCase_				(		lowercase__=None     ,     lowercase__=None		)		->						List[str]:






        """simple docstring"""





        _snake_case		:	Tuple					     =     Graph()
        if vertices is None:
              _snake_case		:	Tuple					     =     []
        if edges is None:
              _snake_case		:	List[str]					     =     []
        for vertex in vertices:
              g.add_vertex(UpperCAmelCase_		)
        for edge in edges:
              g.add_edge(*UpperCAmelCase_		)
        return g





  class lowerCamelCase						:







    def __init__(		self		)		->						Optional[Any]:






          """simple docstring"""





          _snake_case		:	int					     =     {}
          _snake_case		:	List[str]					     =     {}







    def __len__(		self		)		->						Union[str, Any]:






          """simple docstring"""





          return len(self.parent		)







    def 				UpperCAmelCase_				(		self     ,     lowercase__		)		->						Union[str, Any]:






          """simple docstring"""





          if item in self.parent:
                return self.find(UpperCAmelCase_		)

          _snake_case		:	List[Any]					     =     item
          _snake_case		:	Dict					     =     0
          return item







    def 				UpperCAmelCase_				(		self     ,     lowercase__		)		->						str:






          """simple docstring"""





          if item not in self.parent:
                return self.make_set(UpperCAmelCase_		)
          if item != self.parent[item]:
                _snake_case		:	List[str]					     =     self.find(self.parent[item]		)
          return self.parent[item]







    def 				UpperCAmelCase_				(		self     ,     lowercase__     ,     lowercase__		)		->						Dict:






          """simple docstring"""





          _snake_case		:	List[str]					     =     self.find(UpperCAmelCase_		)
          _snake_case		:	Tuple					     =     self.find(UpperCAmelCase_		)

          if roota == roota:
                return roota

          if self.rank[roota] > self.rank[roota]:
                _snake_case		:	Union[str, Any]					     =     roota
                return roota

          if self.rank[roota] < self.rank[roota]:
                _snake_case		:	Any					     =     roota
                return roota

          if self.rank[roota] == self.rank[roota]:
                self.rank[roota] += 1
                _snake_case		:	Dict					     =     roota
                return roota
          return None







  @staticmethod
  def 				UpperCAmelCase_				(		lowercase__		)		->						List[Any]:






        """simple docstring"""





        _snake_case		:	Optional[Any]					     =     graph.num_vertices

        _snake_case		:	Tuple					     =     Graph.UnionFind()
        _snake_case		:	Optional[int]					     =     []
        while num_components > 1:
              _snake_case		:	Tuple					     =     {}
              for vertex in graph.get_vertices():
                    _snake_case		:	Optional[Any]					     =     -1

              _snake_case		:	int					     =     graph.get_edges()
              for edge in edges:
                    _snake_case		:	str					     =     edge
                    edges.remove((tail, head, weight)		)
              for edge in edges:
                    _snake_case		:	Optional[Any]					     =     edge
                    _snake_case		:	Union[str, Any]					     =     union_find.find(UpperCAmelCase_		)
                    _snake_case		:	List[Any]					     =     union_find.find(UpperCAmelCase_		)
                    if seta != seta:
                          if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
                                _snake_case		:	Optional[Any]					     =     [head, tail, weight]

                          if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
                                _snake_case		:	Tuple					     =     [head, tail, weight]
              for vertex in cheap_edge:
                    if cheap_edge[vertex] != -1:
                          _snake_case		:	Union[str, Any]					     =     cheap_edge[vertex]
                          if union_find.find(UpperCAmelCase_		) != union_find.find(UpperCAmelCase_		):
                                union_find.union(UpperCAmelCase_     ,     UpperCAmelCase_		)
                                mst_edges.append(cheap_edge[vertex]		)
                                _snake_case		:	int					     =     num_components - 1
        _snake_case		:	Dict					     =     Graph.build(edges=UpperCAmelCase_		)
        return mst









'''simple docstring'''

from __future__ import annotations




def    _a    (							lowerCAmelCase_			,      lowerCAmelCase_ = None			,      lowerCAmelCase_ = None	):





      """simple docstring"""



      if start is None:
            _snake_case		:	Optional[Any]					     =     0

      if end is None:
            _snake_case		:	Any					     =     len(lowerCAmelCase_	) - 1

      if start >= end:
            return

      _snake_case		:	Optional[Any]					     =     (start + end) // 2

      slowsort(lowerCAmelCase_			,      lowerCAmelCase_			,      lowerCAmelCase_	)
      slowsort(lowerCAmelCase_			,      mid + 1			,      lowerCAmelCase_	)

      if sequence[end] < sequence[mid]:
            _snake_case     ,							_snake_case		:	int					     =     sequence[mid], sequence[end]

      slowsort(lowerCAmelCase_			,      lowerCAmelCase_			,      end - 1	)


if __name__ == "__main__":
   from doctest import testmod

   testmod()


