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