割点与割边

· · 算法·理论

low值

对于一个无向连通图 G ,我们任选一点出发对其进行 dfs 遍历,在遍历的过程中,对于一条无向边 u-v ,当我们从 u 点到达 v 时

显然所有的有效边构成一棵以出发点为根的树

我们规定对于有效边,只允许从父亲走向儿子,对于无效边,我们至多经过一条,并且定义

我们讨论 low_u 的转移式

```C++ void tarjan(int u,int e_in){ dfn[u]=low[u]=++dfc; for(int i=head[u];~i;i=e[i].nxt){ if(i==(e_in^1)) continue;//^的优先级非常小,一定记得加括号 int v=e[i].to; if(!dfn[v]){ tarjan(v,i); low[u]=min(low[u],low[v]); } else low[u]=min(low[u],dfn[v]); } } ``` ## 割点与割边 割点:将任意点 $u$ 及其连接的所有边删除后,图 $G$ 不连通,则点 $u$ 为割点 割边:将任意边 $u-v$ 删除后,图 $G$ 不连通,则边 $u-v$ 为割边,显然割边必为有效边 点双联通图:不存在割点的无向连通图 边双联通图:不存在割边的无向连通图 割点的判定: - $u$ 为出发点,且 $dfs$ 树中 $u$ 点的子节点数量 $>1

割边的判定:

时间复杂度为 O(n+m)

参考代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+10;
struct edge{
    int to,val,nxt;
}e[maxn<<1];
int head[maxn],tot=2;
void addedge(ll u,ll v,ll w){
    e[tot]=edge{v,w,head[u]};head[u]=tot++;
    e[tot]=edge{u,w,head[v]};head[v]=tot++;
}
int root,dfn[maxn],low[maxn],dfc,n,m;
bool p_cut[maxn],e_cut[maxn<<1];//p_cut[i]=1则第i个点为割点,e_cut[2*i]=e_cut[2*i+1]=1则第i条边为割边 
void tarjan(int u,int e_in){
    dfn[u]=low[u]=++dfc;
    int child=0;
    for(int i=head[u];~i;i=e[i].nxt){
        if(i==(e_in^1)) continue;//^的优先级非常小,一定记得加括号 
        int v=e[i].to;
        if(!dfn[v]){
            child++;
            tarjan(v,i);
            low[u]=min(low[u],low[v]);
            if(dfn[u]<=low[v]&&u!=root) p_cut[u]=1;//割点(根要特判)
            if(dfn[u]<low[v]) e_cut[i]=e_cut[i^1]=1;//割边 
        }
        else low[u]=min(low[u],dfn[v]);
    }
    if(u==root&&child>=2) p_cut[u]=1;//特判根 
}
int main(){
    memset(head,-1,sizeof(head));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        addedge(u,v,w);
    }
    for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(root=i,-1);
}