Sum of dependencies in a graph | To add an edge ; Find the sum of all dependencies ; Just find the size at each vector 's index ; Driver code
def addEdge ( adj , u , v ) : NEW_LINE INDENT adj [ u ] . append ( v ) NEW_LINE DEDENT def findSum ( adj , V ) : NEW_LINE INDENT sum = 0 NEW_LINE for u in range ( V ) : NEW_LINE INDENT sum += len ( adj [ u ] ) NEW_LINE DEDENT return sum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT V = 4 NEW_LINE adj = [ [ ] for i in range ( V ) ] NEW_LINE addEdge ( adj , 0 , 2 ) NEW_LINE addEdge ( adj , 0 , 3 ) NEW_LINE addEdge ( adj , 1 , 3 ) NEW_LINE addEdge ( adj , 2 , 3 ) NEW_LINE print ( " Sum ▁ of ▁ dependencies ▁ is " , findSum ( adj , V ) ) NEW_LINE DEDENT