public static < T extends GraphNode < T > > int countAllDistinct ( T node ) { if ( node == null ) return 0 ; return collectAllNodes ( node , new HashSet < T > ( ) ) . size ( ) ; }
Counts all distinct nodes in the graph reachable from the given node . This method can properly deal with cycles in the graph .