human
Find the winner of the match | Multiple Queries | Function to add edge between two nodes.
Function returns topological order of given graph.
Indeg vector will store indegrees of all vertices.
Answer vector will have our final topological order.
Visited will be true if that vertex has been visited.
q will store the vertices that have indegree equal to zero.
Iterate till queue is not empty.
Push the front of queue to answer.
For all neighbours of u , decrement their indegree value.
If indegree of any vertex becomes zero and it is not marked then push it to queue.
Mark this vertex as visited.
Return the resultant topological order.
Function to return the winner between u and v.
Player who comes first wins.
Driver code.
Total number of players.
Build the graph add ( adj , x , y ) means x wins over y.
Resultant topological order in topotable.
Queries"
How can the above be solved in Python?

=====
Can you provide a code to find the winner of the match and the other steps required?
assistant
#Here is code to find the winner of the match and the other steps required.
 def add ( adj , u , v ) :
	adj [ u ] . append ( v )
def topo ( adj , n ) :
	indeg = [ 0 for i in range ( n ) ]
	for i in range ( n ) :
		for x in adj [ i ] :
			indeg [ x ] += 1
	answer = [ ]
	visited = [ False for i in range ( n ) ]
	q = [ ]
	for i in range ( n ) :
		if ( indeg [ i ] == 0 ) :
			q . append ( i )
			visited [ i ] = True
	while ( len ( q ) != 0 ) :
		u = q [ 0 ]
		answer . append ( u )
		q . remove ( q [ 0 ] )
		for x in adj [ u ] :
			indeg [ x ] -= 1
			if ( indeg [ x ] == 0 and visited [ x ] == False ) :
				q . append ( x )
				visited [ x ] = True
	return answer
def who_wins ( topotable , u , v ) :
	for x in topotable :
		if ( x == u ) :
			return u
		if ( x == v ) :
			return v
if __name__ == ' _ _ main _ _ ' :
	adj = [ [ ] for i in range ( 10 ) ]
	n = 7
	add ( adj , 0 , 1 )
	add ( adj , 0 , 2 )
	add ( adj , 0 , 3 )
	add ( adj , 1 , 5 )
	add ( adj , 2 , 5 )
	add ( adj , 3 , 4 )
	add ( adj , 4 , 5 )
	add ( adj , 6 , 0 )
	topotable = topo ( adj , n )
	print ( who_wins ( topotable , 3 , 5 ) )
	print ( who_wins ( topotable , 1 , 2 ) )