栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

图的连通性

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

图的连通性

强连通分量 tarjan c++14

struct scc{
    const int nn;
    int cnt,idx;
    vector col,dfn,low,stk;
    vector onstk;
    vector > g,comp;
    scc(int n1):nn(n1),cnt(0),idx(0),col(n1),dfn(n1,0),low(n1),stk(n1),onstk(n1,0),g(n1){}
    void add_edge(int u,int v)
    {
        g[u].push_back(v);
    }
    void dfs(int u,int fr)
    {
        dfn[u]=low[u]=++cnt;
        int child=0,time=0;
        for(auto [v,i]:g[u])
        {
            if(v==fr&&time==0)
            {
                time++;
                continue;
            }
            if(!dfn[v])
            {
                child++;
                dfs(v,u);
                if(u==fr&&child>=2)
                    point[u]=1;
                if(u!=fr&&low[v]>=dfn[u]&&child>=1)
                    point[u]=1;
                low[u]=min(low[u],low[v]);
            }
            if(fr!=v)
                low[u]=min(low[u],dfn[v]);
            if(low[v]>dfn[u])
                bridges.push_back(i);
        }
    }
    void solve()
    {
        for(int i=0;i 

割点和桥tarjan

struct Bridge{
    const int nn;
    int cnt;
    vector dfn,low,bridges,point;
    vector > > g;
    Bridge(int n1):nn(n1),cnt(0),dfn(n1,0),low(n1),point(n1,0),g(n1){}
    void add_edge(int u,int v,int i)
    {
        g[u].emplace_back(v,i);
        g[v].emplace_back(u,i);
    }
    void dfs(int u,int fr)
    {
        dfn[u]=low[u]=++cnt;
        int child=0,time=0;
        for(auto [v,i]:g[u])
        {
            if(v==fr&&time==0)
            {
                time++;
                continue;
            }
            if(!dfn[v])
            {
                child++;
                dfs(v,u);
            }
            if(u==fr&&child>=2)
                point[u]=1;
            if(u!=fr&&low[v]>=dfn[u]&&child>=1)
                point[u]=1;
            if(low[v]>dfn[u])
                bridges.push_back(i);
            low[u]=min(low[u],low[v]);
        }
    }
    void solve()
    {
        for(int i=0;i 

强连通分量  c++98

struct scc{
    const int nn;
    int cnt,idx;
    vector col,dfn,low,stk;
    vector onstk;
    vector > g,comp;
    scc(int n1):nn(n1),cnt(0),idx(0),col(n1),dfn(n1,0),low(n1),stk(n1),onstk(n1,0),g(n1){}
    void add_edge(int u,int v)
    {
        g[u].push_back(v);
    }
    void dfs(int u)
    {
        dfn[u]=low[u]=++cnt;
        stk[idx++]=u;
        onstk[u]=true;
        for(int i=0;i a1;
            while(true)
            {
                int v=stk[--idx];
                onstk[v]=false;
                a1.push_back(v);
                if(u==v) 
                    break;
            }
            comp.push_back(a1);
        }
    }
    void solve()
    {
        for(int i=0;i 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1009953.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号