human
Find first undeleted integer from K to N in given unconnected Graph after performing Q queries | Function to perform th Get operation of disjoint set union.
Function to perform the union operation of dijoint set union.
Update the graph [ a ] as b.
Function to perform given queries on set of vertices initially not connected.
Stores the vertices.
Mark every vertices rightmost vertex as i.
Traverse the queries array.
Check if it is first type of the givan query.
Get the parent of a.
Print the answer for the second query.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to find first undeleted integer from K to N in given unconnected Graph after performing Q queries and the other steps required.
 def Get ( graph , a ) :
	if graph [ graph [ a ] ] != graph [ a ] :
		graph [ a ] = Get ( graph , graph [ a ] )
	else :
		return graph [ a ]
def Union ( graph , a , b ) :
	a = Get ( graph , a )
	b = Get ( graph , b )
	graph [ a ] = b
def Queries ( queries , N , M ) :
	graph = [ 0 for i in range ( N + 2 ) ]
	for i in range ( 1 , N + 2 , 1 ) :
		graph [ i ] = i
	for query in queries :
		if ( query [ 0 ] == 1 ) :
			Union ( graph , query [ 1 ] , query [ 1 ] + 1 )
		else :
			a = Get ( graph , query [ 1 ] )
			if ( a == N + 1 ) :
				print ( - 1 )
			else :
				print ( graph [ a ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	N = 5
	queries = [ [ 2 , 1 ] , [ 1 , 1 ] , [ 2 , 1 ] , [ 2 , 3 ] ]
	Q = len ( queries )
	Queries ( queries , N , Q )