


class 	lowerCamelCase_       :



		'''simple docstring'''







		def __init__(				self						)   ->			Any:







					'''simple docstring'''

					__lowercase 					=   0
					__lowercase 					=   0
					__lowercase 					=   {}






		def A      (				self ,       snake_case_						)   ->			Dict:







					'''simple docstring'''

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






		def A      (				self ,       snake_case_ ,       snake_case_ ,       snake_case_						)   ->			Any:







					'''simple docstring'''

					self.add_vertex(snake_case_						)
					self.add_vertex(snake_case_						)

					if head == tail:
								return

					__lowercase 					=   weight
					__lowercase 					=   weight






		def A      (				self						)   ->			str:







					'''simple docstring'''

					__lowercase 					=   self.get_edges()
					for edge in edges:
								__lowercase					, __lowercase					, __lowercase 					=   edge
								edges.remove((tail, head, weight)						)
					for i in range(len(snake_case_						)						):
								__lowercase 					=   list(edges[i]						)

					edges.sort(key=lambda snake_case_						: e[2]						)
					for i in range(len(snake_case_						) - 1						):
								if edges[i][2] >= edges[i + 1][2]:
											__lowercase 					=   edges[i][2] + 1
					for edge in edges:
								__lowercase					, __lowercase					, __lowercase 					=   edge
								__lowercase 					=   weight
								__lowercase 					=   weight






		def __str__(				self						)   ->			Any:







					'''simple docstring'''

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






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







					'''simple docstring'''

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






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







					'''simple docstring'''

					return self.adjacency.keys()






		@staticmethod
		def A      (				snake_case_=None ,       snake_case_=None						)   ->			Optional[int]:







					'''simple docstring'''

					__lowercase 					=   Graph()
					if vertices is None:
								__lowercase 					=   []
					if edges is None:
								__lowercase 					=   []
					for vertex in vertices:
								g.add_vertex(snake_case_						)
					for edge in edges:
								g.add_edge(*snake_case_						)
					return g
		class 	lowerCamelCase_       :



				'''simple docstring'''







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







							'''simple docstring'''

							__lowercase 					=   {}
							__lowercase 					=   {}






				def __len__(				self						)   ->			Any:







							'''simple docstring'''

							return len(self.parent						)






				def A      (				self ,       snake_case_						)   ->			List[str]:







							'''simple docstring'''

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

							__lowercase 					=   item
							__lowercase 					=   0
							return item






				def A      (				self ,       snake_case_						)   ->			Any:







							'''simple docstring'''

							if item not in self.parent:
										return self.make_set(snake_case_						)
							if item != self.parent[item]:
										__lowercase 					=   self.find(self.parent[item]						)
							return self.parent[item]






				def A      (				self ,       snake_case_ ,       snake_case_						)   ->			Optional[Any]:







							'''simple docstring'''

							__lowercase 					=   self.find(snake_case_						)
							__lowercase 					=   self.find(snake_case_						)

							if roota == roota:
										return roota

							if self.rank[roota] > self.rank[roota]:
										__lowercase 					=   roota
										return roota

							if self.rank[roota] < self.rank[roota]:
										__lowercase 					=   roota
										return roota

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






		@staticmethod
		def A      (				snake_case_						)   ->			Dict:







					'''simple docstring'''

					__lowercase 					=   graph.num_vertices

					__lowercase 					=   Graph.UnionFind()
					__lowercase 					=   []
					while num_components > 1:
								__lowercase 					=   {}
								for vertex in graph.get_vertices():
											__lowercase 					=   -1

								__lowercase 					=   graph.get_edges()
								for edge in edges:
											__lowercase					, __lowercase					, __lowercase 					=   edge
											edges.remove((tail, head, weight)						)
								for edge in edges:
											__lowercase					, __lowercase					, __lowercase 					=   edge
											__lowercase 					=   union_find.find(snake_case_						)
											__lowercase 					=   union_find.find(snake_case_						)
											if seta != seta:
														if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
																	__lowercase 					=   [head, tail, weight]

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






def 		lowercase_  (     _UpperCamelCase  ):


			'''simple docstring'''







			__lowercase 					=   len(_UpperCamelCase  )
			__lowercase 					=   len(matrix[0]  )
			__lowercase 					=   min(_UpperCamelCase       ,			_UpperCamelCase  )

			for row in range(_UpperCamelCase  ):
						# Check if diagonal element is not zero
						if matrix[row][row] != 0:
									# Eliminate all the elements below the diagonal
									for col in range(row + 1       ,			_UpperCamelCase  ):
												__lowercase 					=   matrix[col][row] / matrix[row][row]
												for i in range(_UpperCamelCase       ,			_UpperCamelCase  ):
															matrix[col][i] -= multiplier * matrix[row][i]
						else:
									# Find a non-zero diagonal element to swap rows
									__lowercase 					=   True
									for i in range(row + 1       ,			_UpperCamelCase  ):
												if matrix[i][row] != 0:
															__lowercase					, __lowercase 					=   matrix[i], matrix[row]
															__lowercase 					=   False
															break
									if reduce:
												rank -= 1
												for i in range(_UpperCamelCase  ):
															__lowercase 					=   matrix[i][rank]

            # Reduce the row pointer by one to stay on the same row
									row -= 1

			return rank


if __name__ == "__main__":
	import doctest

	doctest.testmod()


