human
Maximum value at each level in an N | Function to find the maximum value at each level of N - ary tree.
Stores the adjacency list.
Create the adjacency list.
Perform level order traversal of nodes at each level.
Push the root node.
Iterate until queue is empty.
Get the size of queue.
Iterate for : all the nodes in the queue currently.
Dequeue an node from queue.
Enqueue the children of dequeued node.
Print the result.
Driver Code.
Number of nodes.
Edges of the N - ary tree.
Given cost.
Function Call"
How can the above be solved in Python?
 ... Give me a code to maximum value at each level in an N and the other steps required?
assistant
#Here is code to maximum value at each level in an N and the other steps required.
 def maxAtLevel ( N , M , Value , Edges ) :
	adj = [ [ ] for i in range ( N ) ]
	for i in range ( M ) :
		u = Edges [ i ] [ 0 ]
		v = Edges [ i ] [ 1 ]
		adj [ u ] . append ( v )
	q = [ ]
	q . append ( 0 )
	while ( len ( q ) ) :
		count = len ( q )
		maxVal = 0
		while ( count ) :
			temp = q [ 0 ]
			q . remove ( q [ 0 ] )
			maxVal = max ( maxVal , Value [ temp ] )
			for i in range ( len ( adj [ temp ] ) ) :
				q . append ( adj [ temp ] [ i ] )
			count -= 1
		print ( maxVal , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	N = 10
	Edges = [ [ 0 , 1 ] , [ 0 , 2 ] , [ 0 , 3 ] , [ 1 , 4 ] , [ 1 , 5 ] , [ 3 , 6 ] , [ 6 , 7 ] , [ 6 , 8 ] , [ 6 , 9 ] ]
	Value = [ 1 , 2 , - 1 , 3 , 4 , 5 , 8 , 6 , 12 , 7 ]
	maxAtLevel ( N , N - 1 , Value , Edges )