Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your first step is correct. Each strongly connected components can be substituted with one vertex, for which starting # of reachable vertices is number of elements in this component. After operation of substituting we get directed acyclic graph. Now for each of this super vertices we want to find how many vertices can be reached from it. One idea would be to sort this graph topologically. After this operation all arrows point into one direction. Without loss of generality we can assume they point to the right, so our graph looks more or less like this:</p> <pre><code>a -&gt; b ----&gt; e -&gt; f -&gt; g \ / -&gt; c -&gt; d - </code></pre> <p>For each vertex we have its starting counter which we got from first phase of assembling vertices from one strongly connected components. What we would like to do now is go from right to left and for each vertex have set of vertices reachable from it. Operation which we need is fast merge of this sets. Here with help comes Find-Union data structure. You can add one more field to usual <code>size</code> and <code>rank</code> which will store # of reachable vertices and update it as you <code>union</code> two sets.</p> <p>This will lead to almost linear time: <code>O(n * alpha(n))</code> where <code>alpha(n)</code> is inverse of Ackermann function which is very very small. For huge data it will not be bigger than <code>5</code>, so you can think of it as constant.</p> <p>I wonder if somebody can make it without <code>alpha</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload