码迷,mamicode.com
首页 > 其他好文 > 详细

无向图求割点

时间:2015-05-15 15:33:42      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

using namespace std;

const int MAXE = 300010;
const int MAXP = 1010;

struct N
{
    int v,next;
}edge[MAXE*2];
int head[MAXP];
int Top;
int high[MAXP];
int low[MAXP];
int subnet[MAXP];
int dfsClock;

void Link(int u,int v)
{
    edge[Top].v = v;
    edge[Top].next = head[u];
    head[u] = Top++;
}

void InitGraph()
{
    dfsClock = 0;
    memset(high,0,sizeof(high));
    memset(low,0,sizeof(low));
    memset(subnet,0,sizeof(subnet));
    memset(head,-1,sizeof(head));
    Top = 0;
}

int dfs(int s,int pre)//dfs结束后,subnet[i]记录的为拿掉第i个点之后的联通分量的个数
{
    int lowu = high[s] = ++dfsClock;

    for(int p = head[s]; p != -1; p = edge[p].next)
    {
        if(high[edge[p].v] == 0)
        {
            int lowv = dfs(edge[p].v,s);
            lowu = min(lowu,lowv);

            if(lowv >= high[s])
                subnet[s]++;
        }
        else if(high[edge[p].v] < high[s] && edge[p].v != pre)
        {
            lowu = min(lowu,high[edge[p].v]);
        }
    }

    if(pre != -1)
        subnet[s]++;

    low[s] = lowu;

    return lowu;
}

无向图求割点

标签:

原文地址:http://blog.csdn.net/zmx354/article/details/45744883

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!