def strongly_connected_components
      raise NotDirectedError,
        "strong_components only works for directed graphs." unless directed?
      vis = TarjanSccVisitor.new(self)
      depth_first_search(vis) { |v| }
      vis
    end
def strongly_connected_components
      raise NotDirectedError,
        "strong_components only works for directed graphs." unless directed?
      vis = TarjanSccVisitor.new(self)
      depth_first_search(vis) { |v| }
      vis
    end
class TarjanSccVisitor
 This is Tarjan's algorithm for strongly connected components, from his
 paper "Depth first search and linear graph algorithms".  It calculates
 the components in a single application of DFS.  We implement the
 algorithm with the help of the DFSVisitor TarjanSccVisitor.

 === Definition

 A _strongly connected component_ of a directed graph G=(V,E) is a
 maximal set of vertices U which is in V, such that for every pair of
 vertices u and  v in U, we have both a path from u to v and a path
 from v to u. That is to say, u and v are reachable from each other.

 @Article{Tarjan:1972:DFS,
   author =       "R. E. Tarjan",
   key =          "Tarjan",
   title =        "Depth First Search and Linear Graph Algorithms",
   journal =      "SIAM Journal on Computing",
   volume =       "1",
   number =       "2",
   pages =        "146--160",
   month =        jun,
   year =         "1972",
   CODEN =        "SMJCAT",
   ISSN =         "0097-5397 (print), 1095-7111 (electronic)",
   bibdate =      "Thu Jan 23 09:56:44 1997",
   bibsource =    "Parallel/Multi.bib, Misc/Reverse.eng.bib",
 }

 The output of the algorithm is recorded in a TarjanSccVisitor _vis_.
 vis.comp_map will contain numbers giving the component ID assigned to
 each vertex. The number of components is vis.num_comp.