human
Write me a code to hierholzer 's Algorithm for directed graph and the other steps required given the following:
Hierholzer 's Algorithm for directed graph | Python3 program to print Eulerian circuit in given directed graph using Hierholzer algorithm.
adj represents the adjacency list of the directed graph edge_count represents the number of edges emerging from a vertex.
find the count of edges to keep track of unused edges.
empty graph Maintain a stack to keep vertices.
vector to store final circuit.
start from any vertex.
Current vertex.
If there 's remaining edge.
Push the vertex.
Find the next vertex using an edge.
and remove that edge.
Move to next vertex.
back - track to find remaining circuit.
Back - tracking.
we 've got the circuit, now print it in reverse.
Driver Code.
Input Graph 1.
Build the edges.
Input Graph 2"
Solution in Python:
assistant
#Here is code to hierholzer 's Algorithm for directed graph and the other steps required.
 def printCircuit ( adj ) :
	edge_count = dict ( )
	for i in range ( len ( adj ) ) :
		edge_count [ i ] = len ( adj [ i ] )
	if len ( adj ) == 0 :
		return
	curr_path = [ ]
	circuit = [ ]
	curr_path . append ( 0 )
	curr_v = 0
	while len ( curr_path ) :
		if edge_count [ curr_v ] :
			curr_path . append ( curr_v )
			next_v = adj [ curr_v ] [ - 1 ]
			edge_count [ curr_v ] -= 1
			adj [ curr_v ] . pop ( )
			curr_v = next_v
		else :
			circuit . append ( curr_v )
			curr_v = curr_path [ - 1 ]
			curr_path . pop ( )
	for i in range ( len ( circuit ) - 1 , - 1 , - 1 ) :
		print ( circuit [ i ] , end = " " )
		if i :
			print ( " ▁ - > ▁ " , end = " " )
if __name__ == " _ _ main _ _ " :
	adj1 = [ 0 ] * 3
	for i in range ( 3 ) :
		adj1 [ i ] = [ ]
	adj1 [ 0 ] . append ( 1 )
	adj1 [ 1 ] . append ( 2 )
	adj1 [ 2 ] . append ( 0 )
	printCircuit ( adj1 )
	print ( )
	adj2 = [ 0 ] * 7
	for i in range ( 7 ) :
		adj2 [ i ] = [ ]
	adj2 [ 0 ] . append ( 1 )
	adj2 [ 0 ] . append ( 6 )
	adj2 [ 1 ] . append ( 2 )
	adj2 [ 2 ] . append ( 0 )
	adj2 [ 2 ] . append ( 3 )
	adj2 [ 3 ] . append ( 4 )
	adj2 [ 4 ] . append ( 2 )
	adj2 [ 4 ] . append ( 5 )
	adj2 [ 5 ] . append ( 0 )
	adj2 [ 6 ] . append ( 4 )
	printCircuit ( adj2 )
	print ( )