"Strong connectivity" strong connectivity template Tarjan

Source: Internet
Author: User

I think it's a lot easier than a double-connected Tarjan. The thought and the double connected component are the same pattern.

#include <cstdio> #include <cstring> #include <cstdlib> #include <stack>using namespace std; const int N = 1e5;int Dfn[n], Scc_id[n];int deep, scc_cnt;stack <int> s;int dfs (int u) {int Lowu = Dfn[u] = ++dee    P    S.push (U);        for (int i = head[u]; ~i; i = e[i].next) {int v = E[I].V;            if (!dfn[v]) {int LOWV = DFS (v);        Lowu = min (Lowu, LOWV);        } else if (!scc_id[v]) {///attached to the stack are not yet labeled ancestors Lowu = Min (Lowu, dfn[v]);        }//uses the points in the current SCC to update} if (Lowu = = Dfn[u]) {//Only the points first found satisfy this condition scc_cnt++;            while (1) {int x = S.top (); S.pop ();            SCC_ID[X] = scc_cnt;        if (x = = u) break; }} return Lowu;}    void Tarjan () {for (int i = 0; i < n; i++) {dfn[i] = scc_id[i] = 0;    } deep = scc_cnt = 0;    for (int i = 0; i < n; i++) {if (!dfn[i]) DFS (i); }}int Main () {return 0;}


Strong connectivity strong connectivity template Tarjan

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.