//
// main.cpp
// Richard
//
// Created by 邵金杰 on 16/8/18.
// Copyright © 2016年 邵金杰. All rights reserved.
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=200+10;
vector<vector<int> > G(maxn);
int low[maxn],dfn[maxn],Father[maxn],isCutVectex[maxn];
int n,m;
int idex=0;
void Tarjan(int u,int father)
{
Father[u]=father;
low[u]=dfn[u]=idex++;
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i];
if(!dfn[v])
{
Tarjan(v,u);
low[u]=min(low[u],low[v]);
}
else if(v!=father)
{
low[u]=min(low[u],dfn[v]);
}
}
}
void Count()
{
memset(isCutVectex,0,sizeof(isCutVectex));
int nRootSons=0;
for(int i=2;i<=n;i++)
{
int v=Father[i];
if(v==1) nRootSons++;
else
{
if(dfn[v]<=low[i])
isCutVectex[v]=1;
}
}
if(nRootSons>1) isCutVectex[1]=1;
for(int i=1;i<=n;i++)
if(isCutVectex[i]) printf("%d\n",i);
for(int i=1;i<=n;i++)
{
int v=Father[i];
if(v>0&&dfn[v]<low[i])
printf("%d,%d\n",v,i);
}
}
int main()
{
int a,b;
scanf("%d%d",&n,&m);
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));
memset(Father,0,sizeof(Father));
Tarjan(1,0);
Count();
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
//1
//4
//5
//7
//5,8
//4,9
//7,10
求割点和桥模版
最新推荐文章于 2021-07-21 17:04:39 发布