




import math





class 			__snake_case  :




					def __init__(       self   ,	__UpperCamelCase		)					->  List[Any]:



									'''simple docstring'''







									snake_case__ :     Optional[int] 							=				len(__UpperCamelCase		)
									snake_case__ :     List[str] 							=				[0] * (
									    4 * self.N
									)  # approximate the overall size of segment tree with array N
									self.build(1   ,	0   ,	self.N - 1		)




					def       __a      (       self   ,	__UpperCamelCase		)					->  Dict:



									'''simple docstring'''







									return idx * 2




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



									'''simple docstring'''







									return idx * 2 + 1




					def       __a      (       self   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase		)					->  List[Any]:  # noqa: E741



									'''simple docstring'''







									if l == r:
													snake_case__ :     List[str] 							=				A[l]
									else:
													snake_case__ :     Dict 							=				(l + r) // 2
													self.build(self.left(__UpperCamelCase		)   ,	__UpperCamelCase   ,	__UpperCamelCase		)
													self.build(self.right(__UpperCamelCase		)   ,	mid + 1   ,	__UpperCamelCase		)
													snake_case__ :     Union[str, Any] 							=				max(self.st[self.left(__UpperCamelCase		)]   ,	self.st[self.right(__UpperCamelCase		)]		)




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



									'''simple docstring'''







									return self.update_recursive(1   ,	0   ,	self.N - 1   ,	a - 1   ,	b - 1   ,	__UpperCamelCase		)




					def       __a      (       self   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase		)					->  Dict:  # noqa: E741



									'''simple docstring'''







									if r < a or l > b:
													return True
									if l == r:
													snake_case__ :     Any 							=				val
													return True
									snake_case__ :     Tuple 							=				(l + r) // 2
									self.update_recursive(self.left(__UpperCamelCase		)   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase		)
									self.update_recursive(self.right(__UpperCamelCase		)   ,	mid + 1   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase		)
									snake_case__ :     Optional[Any] 							=				max(self.st[self.left(__UpperCamelCase		)]   ,	self.st[self.right(__UpperCamelCase		)]		)
									return True




					def       __a      (       self   ,	__UpperCamelCase   ,	__UpperCamelCase		)					->  Optional[Any]:



									'''simple docstring'''







									return self.query_recursive(1   ,	0   ,	self.N - 1   ,	a - 1   ,	b - 1		)




					def       __a      (       self   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase		)					->  str:  # noqa: E741



									'''simple docstring'''







									if r < a or l > b:
													return -math.inf
									if l >= a and r <= b:
													return self.st[idx]
									snake_case__ :     Optional[int] 							=				(l + r) // 2
									snake_case__ :     int 							=				self.query_recursive(self.left(__UpperCamelCase		)   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase		)
									snake_case__ :     Tuple 							=				self.query_recursive(self.right(__UpperCamelCase		)   ,	mid + 1   ,	__UpperCamelCase   ,	__UpperCamelCase   ,	__UpperCamelCase		)
									return max(__UpperCamelCase   ,	__UpperCamelCase		)




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



									'''simple docstring'''







									snake_case__ :     Tuple 							=				[]
									for i in range(1   ,	N + 1		):
													show_list += [self.query(__UpperCamelCase   ,	__UpperCamelCase		)]
									print(__UpperCamelCase		)


if __name__ == "__main__":
				lowerCAmelCase__					:       Dict		=       [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
				lowerCAmelCase__					:       Optional[Any]		=       15
				lowerCAmelCase__					:       Dict		=       SegmentTree(A)
				print(segt.query(4, 6))
				print(segt.query(7, 11))
				print(segt.query(7, 12))
				segt.update(1, 3, 1_11)
				print(segt.query(1, 15))
				segt.update(7, 8, 2_35)
				segt.show_data()



from __future__ import annotations

import random

# Adjacency list representation of this graph:
# https://en.wikipedia.org/wiki/File:Single_run_of_Karger%E2%80%99s_Mincut_algorithm.svg
lowerCAmelCase__					:       Dict		=       {
    '''1''': ['''2''', '''3''', '''4''', '''5'''],
    '''2''': ['''1''', '''3''', '''4''', '''5'''],
    '''3''': ['''1''', '''2''', '''4''', '''5''', '''10'''],
    '''4''': ['''1''', '''2''', '''3''', '''5''', '''6'''],
    '''5''': ['''1''', '''2''', '''3''', '''4''', '''7'''],
    '''6''': ['''7''', '''8''', '''9''', '''10''', '''4'''],
    '''7''': ['''6''', '''8''', '''9''', '''10''', '''5'''],
    '''8''': ['''6''', '''7''', '''9''', '''10'''],
    '''9''': ['''6''', '''7''', '''8''', '''10'''],
    '''10''': ['''6''', '''7''', '''8''', '''9''', '''3'''],
}
def 			UpperCamelCase__						(    A__   )       -> set[tuple[str, str]]:
				snake_case__ :     Tuple 							=				{node: {node} for node in graph}

				snake_case__ :     Tuple 							=				{node: graph[node][:] for node in graph}

				while len(A__   ) > 2:
								# Choose a random edge.
								snake_case__ :     Union[str, Any] 							=				random.choice(list(graph_copy.keys()   )   )
								snake_case__ :     Any 							=				random.choice(graph_copy[u]   )

								# Contract edge (u, v) to new node uv
								snake_case__ :     Tuple 							=				u + v
								snake_case__ :     Dict 							=				list(set(graph_copy[u] + graph_copy[v]   )   )
								uv_neighbors.remove(A__   )
								uv_neighbors.remove(A__   )
								snake_case__ :     Optional[Any] 							=				uv_neighbors
								for neighbor in uv_neighbors:
												graph_copy[neighbor].append(A__   )

								snake_case__ :     Tuple 							=				set(contracted_nodes[u].union(contracted_nodes[v]   )   )

								# Remove nodes u and v.
								del graph_copy[u]
								del graph_copy[v]
								for neighbor in uv_neighbors:
												if u in graph_copy[neighbor]:
																graph_copy[neighbor].remove(A__   )
												if v in graph_copy[neighbor]:
																graph_copy[neighbor].remove(A__   )

    # Find cutset.
				snake_case__ :     Tuple 							=				[contracted_nodes[node] for node in graph_copy]
				return {
				    (node, neighbor)
				    for node in groups[0]
				    for neighbor in graph[node]
				    if neighbor in groups[1]
				}


if __name__ == "__main__":
				print(partition_graph(TEST_GRAPH))


