Number of sink nodes in a graph | C # program to count number if sink nodes ; Return the number of Sink NOdes . ; Array for marking the non - sink node . ; Marking the non - sink node . ; Counting the sink nodes . ; Driver Code
using System ; class GFG { static int countSink ( int n , int m , int [ ] edgeFrom , int [ ] edgeTo ) { int [ ] mark = new int [ n + 1 ] ; for ( int i = 0 ; i < m ; i ++ ) mark [ edgeFrom [ i ] ] = 1 ; int count = 0 ; for ( int i = 1 ; i <= n ; i ++ ) if ( mark [ i ] == 0 ) count ++ ; return count ; } public static void Main ( String [ ] args ) { int n = 4 , m = 2 ; int [ ] edgeFrom = { 2 , 4 } ; int [ ] edgeTo = { 3 , 3 } ; Console . WriteLine ( countSink ( n , m , edgeFrom , edgeTo ) ) ; } }