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

无向图求桥,允许重复边

时间:2015-05-15 17:49:23      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:

#include <iostream>
#include <map>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>

#define LL long long
#define INF 0x3f3f3f3f
#define Mod  1000000007
#define Seed1 31
#define Seed2 37
#define EPS (1e-8)

using namespace std;

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

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

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

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

int dfs(int s,int pre)
{
    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,p);
            lowu = min(lowu,lowv);

            if(lowv == high[edge[p].v])
            {
                edge[p].isbridge = true;
                edge[p^1].isbridge = true;
            }
        }
        else if(high[edge[p].v] < high[s] && (p^1) != pre)
        {
            lowu = min(lowu,high[edge[p].v]);
        }
    }


    low[s] = lowu;

    return lowu;
}

无向图求桥,允许重复边

标签:

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

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