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.
count = 0 NEW_LINE for it in node : NEW_LINE INDENT count += len ( Graph [ ( it ) ] ) NEW_LINE DEDENT count //= 2 NEW_LINE if ( count == len ( node ) - 1 ) : NEW_LINE number_of_nodes += 1 NEW_LINE return number_of_nodes NEW_LINE