human
Graph implementation using STL for competitive programming | Set 2 ( Weighted graph ) | To add an edge.
Print adjacency list representaion ot graph.
Driver code"
Solution in Python:
 What is a code to graph implementation using STL for competitive programming and the other steps required?
assistant
#Here is code to graph implementation using STL for competitive programming and the other steps required.
 def addEdge ( adj , u , v , wt ) :
	adj [ u ] . append ( [ v , wt ] )
	adj [ v ] . append ( [ u , wt ] )
	return adj
def printGraph ( adj , V ) :
	v , w = 0 , 0
	for u in range ( V ) :
		print ( " Node " , u , " makes ▁ an ▁ edge ▁ with " )
		for it in adj [ u ] :
			v = it [ 0 ]
			w = it [ 1 ]
			print ( " 	 Node " , v , " with ▁ edge ▁ weight ▁ = " , w )
		print ( )
if __name__ == ' _ _ main _ _ ' :
	V = 5
	adj = [ [ ] for i in range ( V ) ]
	adj = addEdge ( adj , 0 , 1 , 10 )
	adj = addEdge ( adj , 0 , 4 , 20 )
	adj = addEdge ( adj , 1 , 2 , 30 )
	adj = addEdge ( adj , 1 , 3 , 40 )
	adj = addEdge ( adj , 1 , 4 , 50 )
	adj = addEdge ( adj , 2 , 3 , 60 )
	adj = addEdge ( adj , 3 , 4 , 70 )
	printGraph ( adj , V )