• Day algorithm [more] • 26th issue of graph theory: strong connectivity + Tarjan algorithm (a)

Preface ▎

  Always wanted to study this thing, that is difficult, and found much better than this.

  On the basis of these figures will be long on it.

▎ strongly connected

"define"

  Now called strongly connected, then it must have strong connectivity.

  Strong communication: refers to the figure, two vertices can be reached in a mutual, so we call strongly connected;

  Strong graph: In a directed graph, any two points can reach each other, then we say this figure is a strongly connected graph;

  Strongly connected components: in a directed graph (not necessarily strongly connected graph), there must be many subgraphs are strongly connected graph, in particular, a single point is also strongly connected graph, strongly connected components and the maximum is divided strongly connected graph.

  The red box are three strongly connected components:

  

"dfs & directed graph"

  FIG dfs traversal if used, it would look like a tree form.

  The principle is very simple, a departure from any vertex, continues to expand, has traversed so it is no longer traversed, until I can not continue to traverse (or may not be connected to a bit).

  There are many relationships between the current tree node and expand the tree out of the side of them.

  Therefore, after this knowledge, we have to figure out some concepts:

  Suppose the current node u.

  ① branches Edge: u is extended by the edges, and have not visited;

  ② the front side: side directed DFS neutron tree node in the tree;

  ③ After the edges: directed DFS tree father's side;

  ④ fork horizontal edge: edge directed DFS non-child tree tree.

"relationship of judgment."

  First of all the provisions of this: the current node u, expand node v, low storage array is currently away from the nearest root node number, dfn is the number of the current array of storage nodes visited node and its sub-tree.

  Consider the following diagram:

    

  The current node number is 5, then:

  ① branch side: A side have not visited yet, as the side branch;

  ② the front edge: B side dfn [v]> dfn [u], described in the subtree, then this is the side of a front;

  After the edge ③: C have visited the side, and not in the subtree on the stack, so that after a directed edge;

  ④ lateral edge fork: D side has not visited in the subtree, and it has been the stack, it is a horizontal cross edge.

▎Tarjan algorithm

『什么是Tarjan算法?』

  一种由Robert Tarjan提出的求解有向图强连通分量的线性时间的算法。

  Tarjan算法是基于对图深度优先搜索的算法,每个强连通分量为搜索树中的一棵子树。搜索时,把当前搜索树中未处理的节点加入一个堆栈,回溯时可以判断栈顶到栈中的节点是否为一个强连通分量。(copy自百度)

『算法核心』

  对于一条边(u,v),我们在之前的讲解中已经提到了dfn和low数组的意思。

  那么初始状态下:low[u]=dfn[u],这应该很好想,初始状态下离根节点最近的节点编号先赋值为自己遍历的编号,和并查集的初始化类似。

  每一次扩展时,若边为树枝边,那么我们就使用low[v]来更新low[u],如果是后向边,那么我们就使用dfn[v]来更新。

  当low[u] == dfn[u]时,就是一个分割点,要把u之后入栈的元素及u全部弹出栈。

  可能有些难理解,推荐一篇别人的博客,图解画得很好,链接在此

  当然,问tarjan算法也会告诉你图解的,小编就不画了。

Guess you like

Origin www.cnblogs.com/TFLS-gzr/p/11271586.html