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