Iterating over the node set to count the number of nodes visited after making the graph directed and storing it in the variable count . If count / 2 == number of nodes - 1 , then increment count by 1.
int count = 0 ; foreach ( int it in node ) count += Graph [ ( it ) ] . Count ; count /= 2 ; if ( count == node . Count - 1 ) number_of_nodes ++ ; } } return number_of_nodes ; }