graph-SCC

strongly connected component(SCC): 里面的任一对顶点都是互相可达的。

一个有向图,将每个SCC缩成一个点,那么这个图就变成了DAG(有向无环图)。

原图进行DFS之后,使post (u)最大的u点必然在source中.

如果C和C'是两个不同的SCC,一条边从C到C',那么C中post值最大的值一定比C'中最大的要大。

寻找SCC的算法:

1 call DFS (G) to compute finishing times post[u] for each vertex u

2 compute GT // GT 即对G中的边取反后得到的图。取反后,SCC内部仍然是通的,但SCC之间就不再是连通的了。
3 call DFS (GT), but in the main loop of DFS, consider the vertices in order of decreasing post[u]

4 output the vertices of each tree in the depth-first forest formed in step 3 as a SCC

计算GT的时间:O(V+E)
两次DFS的时间:O(V+E)
总时间: O(V+E)

算法实现:

 


 

posted @ 2017-03-19 17:01  陆离可  阅读(455)  评论(0编辑  收藏  举报