求无向连通图的点双连通分支(不包含割点的极大连通子图)

//
//  main.cpp
//  Richard
//
//  Created by 邵金杰 on 16/8/18.
//  Copyright © 2016年 邵金杰. All rights reserved.
//



#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int maxn=200+10;
struct edge{
    int u,v;
    edge(int u,int v): u(u),v(v) {}
};
vector<edge> edges;
vector<vector<int> > G(maxn);
int dfn[maxn],low[maxn];
int n,m;
int idex=0,kase=0;
void Tarjan(int u,int father)
{
    low[u]=dfn[u]=++idex;
    for(int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        if(!dfn[v])
        {
            edges.push_back(edge(u,v));
            Tarjan(v,u);
            low[u]=min(low[u],low[v]);
            edge temp(0,0);
            if(dfn[u]<=low[v])
            {
                printf("Block No: %d\n",++kase);
                do{
                    temp=edges[edges.size()-1];
                    edges.pop_back();
                    printf("%d,%d\n",temp.u,temp.v);
                }while(!(temp.u==u&&temp.v==v));
            }
        }
        else{
            if(v!=father)
            {
                low[u]=min(low[u],dfn[v]);
                if(dfn[u]>dfn[v])
                    edges.push_back(edge(u,v));
            }
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    int a,b;
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
    Tarjan(1,0);
    return 0;
}

//input
//11 13
//1 2
//1 4
//1 5
//1 6
//2 11
//2 3
//4 3
//4 9
//5 8
//5 7
//6 7
//7 10
//11 3
//output
//Block No: 1
//4,9
//Block No: 2
//4,1
//3,4
//3,2
//11,3
//2,11
//1,2
//Block No: 3
//5,8
//Block No: 4
//7,10
//Block No: 5
//6,1
//7,6
//5,7
//1,5

//input
//8 9
//1 2
//1 3
//1 5
//3 5
//2 4
//4 6
//4 7
//6 8
//7 8
//output
//Block No: 1
//7,4
//8,7
//6,8
//4,6
//Block No: 2
//2,4
//Block No: 3
//1,2
//Block No: 4
//5,1
//3,5
//1,3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值