Number of sink nodes in a graph | Return the number of Sink NOdes . ; Array for marking the non - sink node . ; Marking the non - sink node . ; Counting the sink nodes . ; Driver Code
def countSink ( n , m , edgeFrom , edgeTo ) : NEW_LINE INDENT mark = [ 0 ] * ( n + 1 ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT mark [ edgeFrom [ i ] ] = 1 NEW_LINE DEDENT count = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( not mark [ i ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE m = 2 NEW_LINE edgeFrom = [ 2 , 4 ] NEW_LINE edgeTo = [ 3 , 3 ] NEW_LINE print ( countSink ( n , m , edgeFrom , edgeTo ) ) NEW_LINE DEDENT