Strongly connected components and connected components of undirected graphs

Source: Internet
Author: User

Strongly connected components and connected components of undirected graphs
 

This blog has a very big conceptual error (the algorithm is not correct). The correct version is available here.

 

 

 

 

Before learning the strong connected components of an undirected graph

First, you must understand the strong Unicom component of the directed graph.

 

In the past, too naive was called the dual-link QWQ component ..

 

Definition

For any two points, if there are at least two paths that do not overlap with each other, so that these two points can reach each other, then these two points belong to the same strong Unicom component.

For example

 

 

In this figure,

$, 3 $ is a strong Unicom component

$4 $ is a strongly connected component, because $3, 4 $ only has one path that can reach each other.

 

 

Implementation

Similar to the strongly connected component of a Directed Graph

All are implemented using the Tarjan algorithm.

In order to find the strong link weight of an undirected graph, we are not allowed to walk through the edge.

Therefore, we need to record a father during the Tarjan process.

Only the target node is not the father node.

int Tarjan(int now,int fa){dfn[now]=low[now]=++tot;vis[now]=1;s.push(now);for(int i=head[now];i!=-1;i=edge[i].nxt){if(dfn[edge[i].v]==0)Tarjan(edge[i].v,now),low[now]=min(low[now],low[edge[i].v]);else if(vis[edge[i].v]&&edge[i].v!=fa)low[now]=min(low[now],dfn[edge[i].v]);}if(dfn[now]==low[now]){int top;++colornum;do{top=s.top();color[top]=colornum;vis[top]=0;s.pop();}while(top!=now);}}

 

 

Example

Put a question for our exam

Here
Go down to the third question

 

 

 

 

 

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.