Incomplete analysis of Tarjan for strong connected components (SCC) __noip

Source: Internet
Author: User

Define dfn[] For each point of the timestamp (search order), low[] The DFN of the lowest DFN ancestor that can be traced to each point, that is, the most shallow ancestor
Prove I really will not, can only own yy, do not make sure that every sentence is correct, if my analysis has errors please must point out ...
Go to DFS first. A graph with an SCC must have a ring, so when you search for a point that has been visited, we have found a ring, at this time all the points on this ring must be strong unicom (as the earth is round, so all along in a direction can return to the starting point), this ring is a strong unicom child map, The last thing we looked for was a great ring.
To save the read point with the stack, each encounter with a dfn==low point indicates that the ancestor of the ring was found, bouncing the ancestor and the point after which it was added to the stack, and marking the flag[pop-up point]=false,
Flag is used to make sure that a ring is picked out so that the other rings are not affected by one of the one-way edges of a ring on the ring that should be removed .

void Tarjan (int x) {
    dfn[x] = low[x] = ++count;
    S[++top] = x;
    FLAG[X] = 1;
    for (int i=last[x]; i; i=e[i].next) {
        int v = e[i].to;
            if (!dfn[v]) {
                Tarjan (v);
                if (Low[x] > Low[v]) 
                    low[x] = low[v];
            else if (Dfn[v] < low[x] && Flag[v]) 
                low[x] = dfn[v];
    if (dfn[x] = = Low[x]) {
        int j,k = 0;
        do{
            j = s[top--];
            FLAG[J] = 0;
            k++;
        } while (j!=x);
    }
}

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.