Talking about two connected components and strong connected components

Source: Internet
Author: User

At first, I believe that every one will feel a bit puzzled, mainly because the word "weight", of course, if only to understand and use the two terms, you do not have to care about this irrelevant word.

Well, it's time to talk. The so-called double connectivity and strong connectivity, the biggest difference, but also the most essential difference is that the former applies to undirected graphs, while the latter applies to the undirected graph. The concept of the two is the same, that is, a point, B Point, from point A can reach point B, and from point B can reach point A. (if a directed graph must be extended direction to arrive.) )

The two connected components can be subdivided into: point-double connected component, edge-double connected component. The so-called point-to-double connectivity component refers to at least two paths between two points in an undirected graph, and different points in the path (not counting the tail). Different points-two connected components have at most one common point, and this point must be "cut-top". Mention that the cut has to be said here, cutting the top (such as) when the point is deleted, the number of connected blocks will increase. As for what is called the connected block, can be understood as a set of points, if the two points can be directly or indirectly connected to the two points in the same connected block.

As for the side-double connected component, there are at least two paths between two points in an undirected graph, and the edges in the path are different. There must be no bridge in the side-double connected component. The bridge, for example, means that when the edge is deleted, the number of connected blocks increases.

The knowledge of the thing has been finished, the following roughly speaking about the program.

 void  dfs (int   V)     {Node_pointer W;     VISITED[V]  = TRUE;          for  (w = graph[v]; w; w = W->link) {               if  (!visited[w->vertex]) {        DFS (w ->vertex); }}}  void   connect () { for  (int  i = 0 ; i < n; i++ if  (!

Find points-Double connected graphs:

stack<int>s;intnum=1, time=0;intid[ +]={0}; voidTarjan (intXintFA) {Dfn[x]=low[x]=time++;  for(inte=first[x];e!=-1; e=Next[e]) {         if(x!=fa&&dfn[x]<Dfn[v[e]])                         {S.push (e); if(dfn[x]==0) {Tarjan (v[e], x); if(Low[v[e]]<low[x]) low[x]=Low[v[e]]; if(low[v[e]]>=Dfn[x]) {                       intEdge;  Do{s.pop (); Edge=S.top (); Id[u[edge]]=id[v[edge]]=num++; } while(u[edge]!=x| | v[edge]!=V[e]); }            }             Else if(Dfn[v[e]]<low[x]) low[x]=Dfn[v[e]]; }    }}

Find edges-Double connected graphs:

void(intUintFA) {Dfn[u]=low[u]=++Time ; S[top++]=u;  for(inte=first[u];e!=-1; e=Next[e]) {        if(v[e]!=FA) {             if(!Dfn[v[e]])                                 {Tarjan (v[e],u); if(Low[v[e]]<low[u]) low[u]=Low[v[e]]; Else if(low[v[e]]>Dfn[u]) {                      for(s[top]=-1; s[top]!=V[e];) {id[s[--top]]=num; Num++; }                }            }             Else if(Dfn[v[e]]<low[u]) low[u]=Dfn[v[e]]; }    }}

To find strong connected graphs:

voidTarjan (inti) {    intJ; Dfn[i]=low[i]=++Dindex; Instack[i]=true; stap[++stop]=i;  for(Edge *e=v[i];e;e=e->next) {J=e->T; if(!Dfn[j])            {Tarjan (j); if(Low[j]<low[i]) low[i]=Low[j]; }        Else if(Instack[j] && dfn[j]<low[i]) low[i]=Dfn[j]; }        if(dfn[i]==Low[i]) {bcnt++;  Do{J=stap[stop--]; INSTACK[J]=false; BELONG[J]=bcnt; } while(j!=i); }}voidsolve () {Stop=bcnt=dindex=0; memset (DFN,0,sizeof(DFN));  for(intI=1; i<=n;i++)    {        if(!Dfn[i]) Tarjan (i); }}

Thank you for watching my blog, if there are insufficient welcome to put forward, at the same time I hope you can have some gains, thank you.

Talking about two connected components and strong connected components

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.