Shrink strongly connected components

Source: Internet
Author: User

Shrinking the strongly connected component in a directed graph is approximately linear in graph theory.AlgorithmThe most skillful one. Our primary goal is to set a belong value for each vertex, that is, the strongly connected component represented by the vertex to which it belongs. As for recreating the edge of the graph, it is easier to scan all edges to see if they appear in the new graph.

The following method uses DFS to calculate the strongly connected component: For each vertex, set the attributes num, low, used, and alive, and a stack stores the vertices being traversed; each time a vertex is accessed, its num and low are set as the current timestamp, used and alive are set to true, and the vertex is added to the stack. For each side of the vertex, if the end of an edge is not used, access it, and then use the low value of the end to update its low value. For each used and the end of alive, use its num value to update the current value; after accessing the current vertex, if low is equal to num, a strongly connected component is found, which includes all vertices above the current vertex in the stack, write them out of the stack and the belong value. Set alive of the vertex of the stack to false.

Note that the low value here is different from the definition of the low value when the cut top and bridge are used. It is the lowest vertex that is connected to the current vertex in two ways, therefore, alive is used to mark whether the vertex can be reached.

ExampleProgram:Cow. cpp
(Haoi 2006 cow)

A6l 18,200 7 · filed underProgram Park

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.