Sum of dependencies in a graph | C # program to find the sum of dependencies ; To add an edge ; Find the sum of all dependencies ; Just find the size at each vector 's index ; Driver code
using System ; using System . Collections ; class GFG { static void addEdge ( ArrayList [ ] adj , int u , int v ) { adj [ u ] . Add ( v ) ; } static int findSum ( ArrayList [ ] adj , int V ) { int sum = 0 ; for ( int u = 0 ; u < V ; u ++ ) sum += adj [ u ] . Count ; return sum ; } public static void Main ( string [ ] args ) { int V = 4 ; ArrayList [ ] adj = new ArrayList [ V ] ; for ( int i = 0 ; i < V ; i ++ ) { adj [ i ] = new ArrayList ( ) ; } addEdge ( adj , 0 , 2 ) ; addEdge ( adj , 0 , 3 ) ; addEdge ( adj , 1 , 3 ) ; addEdge ( adj , 2 , 3 ) ; Console . Write ( " Sum ▁ of ▁ dependencies ▁ is ▁ " + findSum ( adj , V ) ) ; } }