//
// 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
求无向连通图的点双连通分支(不包含割点的极大连通子图)
最新推荐文章于 2019-05-14 22:47:21 发布