

class 					a	:


						def __init__(							self						):







										'''simple docstring'''


										_UpperCAmelCase							:		int					=     0
										_UpperCAmelCase							:		Dict					=     0
										_UpperCAmelCase							:		Any					=     {}


						def 							_UpperCAmelCase					(							self    ,       A_						):







										'''simple docstring'''


										if vertex not in self.adjacency:
														_UpperCAmelCase							:		Optional[Any]					=     {}
														self.num_vertices += 1


						def 							_UpperCAmelCase					(							self    ,       A_    ,       A_    ,       A_						):







										'''simple docstring'''


										self.add_vertex(SCREAMING_SNAKE_CASE_						)
										self.add_vertex(SCREAMING_SNAKE_CASE_						)

										if head == tail:
														return

										_UpperCAmelCase							:		Dict					=     weight
										_UpperCAmelCase							:		Union[str, Any]					=     weight


						def 							_UpperCAmelCase					(							self						):







										'''simple docstring'''


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

										edges.sort(key=lambda A_						: e[2]						)
										for i in range(len(SCREAMING_SNAKE_CASE_						) - 1						):
														if edges[i][2] >= edges[i + 1][2]:
																		_UpperCAmelCase							:		Optional[Any]					=     edges[i][2] + 1
										for edge in edges:
														_UpperCAmelCase		,				_UpperCAmelCase		,				_UpperCAmelCase							:		int					=     edge
														_UpperCAmelCase							:		Dict					=     weight
														_UpperCAmelCase							:		Union[str, Any]					=     weight


						def __str__(							self						):







										'''simple docstring'''


										_UpperCAmelCase							:		Dict					=     ""
										for tail in self.adjacency:
														for head in self.adjacency[tail]:
																		_UpperCAmelCase							:		Dict					=     self.adjacency[head][tail]
																		string += f'{head} -> {tail} == {weight}\n'
										return string.rstrip("\n"						)


						def 							_UpperCAmelCase					(							self						):







										'''simple docstring'''


										_UpperCAmelCase							:		List[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						):







										'''simple docstring'''


										return self.adjacency.keys()


						@staticmethod
						def 							_UpperCAmelCase					(							A_=None    ,       A_=None						):







										'''simple docstring'''


										_UpperCAmelCase							:		Optional[int]					=     Graph()
										if vertices is None:
														_UpperCAmelCase							:		List[str]					=     []
										if edges is None:
														_UpperCAmelCase							:		List[str]					=     []
										for vertex in vertices:
														g.add_vertex(SCREAMING_SNAKE_CASE_						)
										for edge in edges:
														g.add_edge(*SCREAMING_SNAKE_CASE_						)
										return g

						class 					a	:


												def __init__(							self						):







																'''simple docstring'''


																_UpperCAmelCase							:		int					=     {}
																_UpperCAmelCase							:		Optional[Any]					=     {}


												def __len__(							self						):







																'''simple docstring'''


																return len(self.parent						)


												def 							_UpperCAmelCase					(							self    ,       A_						):







																'''simple docstring'''


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

																_UpperCAmelCase							:		Dict					=     item
																_UpperCAmelCase							:		int					=     0
																return item


												def 							_UpperCAmelCase					(							self    ,       A_						):







																'''simple docstring'''


																if item not in self.parent:
																				return self.make_set(SCREAMING_SNAKE_CASE_						)
																if item != self.parent[item]:
																				_UpperCAmelCase							:		Union[str, Any]					=     self.find(self.parent[item]						)
																return self.parent[item]





												def 							_UpperCAmelCase					(							self    ,       A_    ,       A_						):







																'''simple docstring'''


																_UpperCAmelCase							:		Dict					=     self.find(SCREAMING_SNAKE_CASE_						)
																_UpperCAmelCase							:		List[Any]					=     self.find(SCREAMING_SNAKE_CASE_						)

																if roota == roota:
																				return roota

																if self.rank[roota] > self.rank[roota]:
																				_UpperCAmelCase							:		Optional[int]					=     roota
																				return roota

																if self.rank[roota] < self.rank[roota]:
																				_UpperCAmelCase							:		int					=     roota
																				return roota

																if self.rank[roota] == self.rank[roota]:
																				self.rank[roota] += 1
																				_UpperCAmelCase							:		Optional[int]					=     roota
																				return roota
																return None







						@staticmethod
						def 							_UpperCAmelCase					(							A_						):







										'''simple docstring'''


										_UpperCAmelCase							:		Any					=     graph.num_vertices

										_UpperCAmelCase							:		Dict					=     Graph.UnionFind()
										_UpperCAmelCase							:		str					=     []
										while num_components > 1:
														_UpperCAmelCase							:		Union[str, Any]					=     {}
														for vertex in graph.get_vertices():
																		_UpperCAmelCase							:		Union[str, Any]					=     -1

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

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




"""simple docstring"""




from ..utils import DummyObject, requires_backends





class 			snake_case  (				metaclass=__lowercase ):
							UpperCAmelCase__      =   ['''note_seq''']

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

									"""simple docstring"""







									requires_backends(self							,							['''note_seq''']     )

							@classmethod
							def _lowercase       (cls							,							*SCREAMING_SNAKE_CASE_							,							**SCREAMING_SNAKE_CASE_     ):

									"""simple docstring"""







									requires_backends(cls							,							['''note_seq''']     )







							@classmethod
							def _lowercase       (cls							,							*SCREAMING_SNAKE_CASE_							,							**SCREAMING_SNAKE_CASE_     ):

									"""simple docstring"""







									requires_backends(cls							,							['''note_seq''']     )