Undirected graph cut point cut edge, directed graph strongly connected

Source: Internet
Author: User

Cut Edge: directly search (mark the reverse side), find the mark, and V is the cut edge if the time stamp U-> V is greater than U.

 
For (I = head [u]; I! =-1; I = edge [I]. next) {If (edge [I]. mk) continue; edge [I ^ 1]. mk = 1; V = edge [I]. v; If (! Mark [v]) DFS (V); Dep [u] = f_min (DEP [u], DEP [v]); If (DEP [v]> now [u]) {// edge [I] is a cut edge} edge [I ^ 1]. mk = 0 ;}

Cut point: if the successor node fails to find a point lighter than u, the U is the cut point. If you encounter a V that has not been searched, you can also find the point u that can be searched by V. However, if you encounter a V that has already been searched, the point it can find does not mean that u can also be searched, because V may be the point to be judged, and we cannot pass it. Therefore, the V judgment is slightly different from the above judgment.

 
For (I = head [u]; I! =-1; I = edge [I]. next) {If (edge [I]. mk) continue; edge [I ^ 1]. mk = 1; V = edge [I]. v; If (! Mark [v]) {/* The V */DFS (v) that can be searched out; Dep [u] = f_min (DEP [u], DEP [v]);} else Dep [u] = f_min (DEP [u], now [v]); If (DEP [v]> = now [u]) {// U is the cut point (as long as one V is satisfied)} edge [I ^ 1]. mk = 0 ;}

CodeI forgot to add one point: U is the cut point. If U is the root node, it cannot be regarded as the cut point, but it depends on whether there are two or more V that can be searched out.

Strongly Connected contraction point: you need to create more instk arrays to indicate whether a point is in the current search path (if a searched point is found in an undirected graph, it must be in the current search path, therefore, this array is not required ).

Dep update only requires = f_min (DEP [u], DEP [v.

 
For (I = head [u]; I! =-1; I = edge [I]. Next) {v = edge [I]. V; If (MARK [v]) continue; If (! Instk [v]) DFS (V); Dep [u] = f_min (DEP [u], DEP [v]);} if (DEP [u]> = now [u]) {// until u in the stack is a strongly connected component}

Every time you do this kind of question, you always have to think about it again. The simple method is not very popular with Templates. Let's just summarize it.

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.