求割点和桥模版

//
//  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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值