There appreciated that the algorithm of FIG condensing point tarjan--

 

  Tarjan beginning to learn, the relevant undirected graph cut point, bridge, bilateral two-point reduction point are relatively easy to understand, with the exception of a directed graph point reduction operations unclear. By luoguP2656_ picking mushrooms solve a problem, generally tarjan find out the correctness of the algorithm.

  First released to FIG constricted point tarjan writing function:

  1. tarjan void ( you and) {  
  2.     dfn[u] = low[u] = ++timer;  
  3.     sta[++stp] = u, ins[u] = true;  
  4. for (int i = head[u]; i; i = edge[i].nxt) {  
  5. int v = edge[i].to;  
  6. if (!dfn[v]) {  
  7.             Tarjan (v);  
  8.             low[u] = min(low[u], low[v]);  
  9.         } else if (ins[v])   
  10.             low[u] = min(low[u], dfn[v]);  
  11.     }  
  12. //////////////Dividing line////////////////
  13. if (dfn[u] == low[u]) {  
  14.         ++cnt;  
  15. int x;  
  16. do {  
  17.             x = is [stp--];  
  18.             c[x] = cnt;  
  19.             ins[x] = false;  

        } while (x != u);  

  1.     }  
  2. }  

  The main problem lies in the second part of the function. After traversing all edges u points, first, Why (dfn [u] == low [u]) as a constituent component of the strong communication determination condition? Second, why now remain in the stack after traversing the point u can constitute a strongly connected component?

  We first consider the characteristics of a strongly connected component. When configured with a set point in the figure number are strongly connected, if and only if it satisfies FIG portion wherein any two u, v interworking. Typical structure easy to think of having this feature also has the ring; in fact, the easiest ring strongly connected graph, and (perceptually) any strongly connected components may be simply understood as a plurality of ring interworking It constituted. This is a very important idea. I believe that the strongly connected components simplify the complex is to be understood that the ring can be readily described in more correctness tarjan algorithm.

  Now we are two simple schematic diagram to illustrate the problem.

 

As shown above, FIG showing a case where the simplest ring, u is the starting point of the current tarjan function. We first recursively a, b, c stack, found low values ​​of the three points to the u point on it, rather than their own. tarjan algorithm elaboration of conditions (dfn [u] == low [u]) is: u satisfy this condition, the "root" of a strongly connected component; in other words, u is a root to a subtree searches together form a strongly connected components. So, we observe the correctness of this conclusion lies.

1, for the two points in the sub-tree, if the timestamp is greater than point i meet point j, then i will be able to communicate with the point j by "forward side" (searching side), which is obvious.

2, why i j point you can access the point of it? This is the origin determination conditions (dfn [u] == low [u]) of. Obviously, j point may return to the last point c via the point that one side of u, u and from roots to reach any point i along the front edge.

  At the same time, we can explain to u is the root cause: if we make an edge in the brain c -> a, then a, b, c three is strongly connected, but the communication part and strongly connected with u, then this a set of three can not be constructed (maximum) strongly connected component, a not "root." Conversely, if the subtree rooted at u is still not back to a higher point in the stack and is only reachable u, then the component must be complete.

  图二为子树含两个环的情况,可以认为是更复杂的强连通分量结构。依然,对子树中任意一点v都可以返回到u,然后到达分量中的任意一点,则两个环共同与u构成强连通分量。实际上,任意的强连通结构都符合这个特征,我们总能沿着某条路径回到根,然后到达任意点,而这正是强连通分量的定义。

 

  最后,联想到维护栈的意义:若某些点已经被遍历过而不在栈中,则其参与构成的强连通分量必然已达到最大,不可能与栈中剩余点强连通。典型的例子是横叉边:由当前点可以回到上一个强连通分量中,而那个分量却不存在边能到达当前点,否则这个点早就在那个分量中就被前向边遍历过了。而对于子树中已经弹出的点,一定是各自构成了较小的强连通分量:因为一定存在某个子节点v,使得(dfn[v] == low[v]),即其子树不能回溯到更广的分量范围中。

  可能写得有些啰嗦,不太好明白(只有我自己知道我在说什么),所以欢迎有问题或者其他想法的同学在评论区交流。

 

Guess you like

Origin www.cnblogs.com/TY02/p/11110656.html