zoukankan      html  css  js  c++  java
  • 无向图求边双连通分量/桥

    在无向图中,去掉了i号边,连通块数量增加了,那么i号边就是桥。

    #include<bits/stdc++.h>
    using namespace std;
    #define ls rt<<1
    #define rs (rt<<1)+1
    #define PI acos(-1)
    #define eps 1e-8
    #define ll long long
    #define fuck(x) cout<<#x<<"     "<<x<<endl;
    typedef pair<int,int> pii;
    const int inf=2e9;
    const int maxn=1e6+10;
    int d[4][2]={1,0,-1,0,0,1,0,-1};
    //int lowbit(int x){return x&-x;}
    //void add(int x,int v){while(x<=n)bit[x]+=v,x+=lowbit(x);}
    //int sum(int x){int ans=0;while(x>=1) ans+=bit[x],x-=lowbit(x);return ans;}
    inline ll read() {
        ll s = 0,w = 1;
        char ch = getchar();
        while(!isdigit(ch)) {
            if(ch == '-') w = -1;
            ch = getchar();
        }
        while(isdigit(ch))
            s = s * 10 + ch - '0',ch = getchar();
        return s * w;
    }
    inline void write(ll x) {
        if(x < 0)
            putchar('-'), x = -x;
        if(x > 9)
            write(x / 10);
        putchar(x % 10 + '0');
    }
    int gcd(int x,int y){
        return y==0?x:gcd(y,x%y);
    }
    struct edge{
        int u,v,nxt;
    }e[maxn<<1];
    int head[maxn],dfn[maxn],low[maxn],cnt,n,m;
    vector<int>bri;
    
    void dfs(int now,int fa){
        bool flag=0;
        dfn[now]=low[now]=++cnt;
        for(int i=head[now];i!=-1;i=e[i].nxt){
            int v=e[i].v;
            if(!dfn[v]){
                dfs(v,now);
                low[now]=min(low[now],low[v]);
                if(low[v]>dfn[now]){
                    bri.push_back(i);
                }
            }
            else
                if(v!=fa||flag)
                    low[now]=min(low[now],dfn[v]);
                else
                    flag=1;
        }
    }
    
    int main(){
    
        return 0;
    }

    一个边双连通分量里任意两点有至少两条边不重复路径,即没有桥

    #include<bits/stdc++.h>
    using namespace std;
    #define ls rt<<1
    #define rs (rt<<1)+1
    #define PI acos(-1)
    #define eps 1e-8
    #define ll long long
    #define fuck(x) cout<<#x<<"     "<<x<<endl;
    typedef pair<int,int> pii;
    const int inf=2e9;
    const int maxn=1e6+10;
    int d[4][2]={1,0,-1,0,0,1,0,-1};
    //int lowbit(int x){return x&-x;}
    //void add(int x,int v){while(x<=n)bit[x]+=v,x+=lowbit(x);}
    //int sum(int x){int ans=0;while(x>=1) ans+=bit[x],x-=lowbit(x);return ans;}
    inline ll read() {
        ll s = 0,w = 1;
        char ch = getchar();
        while(!isdigit(ch)) {
            if(ch == '-') w = -1;
            ch = getchar();
        }
        while(isdigit(ch))
            s = s * 10 + ch - '0',ch = getchar();
        return s * w;
    }
    inline void write(ll x) {
        if(x < 0)
            putchar('-'), x = -x;
        if(x > 9)
            write(x / 10);
        putchar(x % 10 + '0');
    }
    int gcd(int x,int y){
        return y==0?x:gcd(y,x%y);
    }
    struct edge{
        int u,v,nxt;
    }e[maxn<<1];
    int head[maxn],dfn[maxn],low[maxn],bcc[maxn],bccn,cnt,n,m;
    vector<int>bri;
    stack<int>sta;
    
    void dfs(int now,int fa){
        bool flag=0;//flag用于处理重边的情况
        dfn[now]=low[now]=++cnt;
        sta.push(now);
        for(int i=head[now];i!=-1;i=e[i].nxt){
            int v=e[i].v;
            if(!dfn[v]){
                dfs(v,now);
                low[now]=min(low[now],low[v]);
            }
            else
                if(v!=fa||flag)
                    low[now]=min(low[now],dfn[v]);
                else
                    flag=1;
        }
        if(low[now]==dfn[now]){
            bccn++;
            for(;;){
                int tmp=sta.top();sta.pop();
                bcc[tmp]=bccn;
                if(tmp==now) break;
            }
        }
    }
    
    int main(){
    
        return 0;
    }
  • 相关阅读:
    uni-app 去除顶部导航栏
    javascript DOM和DOM操作的四种基本方法
    js获取当前时间
    vue自定义事件---拖拽
    富文本去除标签空格
    js贪吃蛇(构造函数)
    vue v-html 富文本解析 空格,换行,图片大小问题
    实验十二 团队项目用户验收评审
    Beta冲刺-第四天
    Beta冲刺-第二天
  • 原文地址:https://www.cnblogs.com/eason9906/p/11754684.html
Copyright © 2011-2022 走看看