无向图求割点

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;
}

时间: 2024-10-31 22:24:31

无向图求割点的相关文章

UVA 315 Network(无向图求割点)

题目大意 A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N. No two places have the same number. The lines are bidirectional and always connect together two pl

无向图求割点 UVA 315 Network

输入数据处理正确其余的就是套强联通的模板了 #include <iostream> #include <cstdlib> #include <cstdio> #include <algorithm> #include <vector> #include <queue> #include <cmath> #include <stack> #include <cstring> using namespa

poj 1144 Network 无向图求割点

Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The lines are bidirectional and always connect

POJ 1144 无向图求割点

学长写的: #include<cstdio>#include<cstdlib>#include<cmath>#include<iostream>#include<algorithm>#include<cstring>#include<vector>using namespace std;#define maxn 10005int dfn[maxn];///代表最先遍历到这个点的时间int low[maxn];///这个点所

B - Network---UVA 315(无向图求割点)

A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N. No two places have the same number. The lines are bidirectional and always connect together two places

(连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)

链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=251 http://poj.org/problem?id=1144 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82833#problem/B 代码: #include<cstdio> #include<

poj 2117 Electricity 【无向图求割点】【求去掉一个点后 图中最多的BCC数目】

Electricity Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4597   Accepted: 1515 Description Blackouts and Dark Nights (also known as ACM++) is a company that provides electricity. The company owns several power plants, each of them sup

poj1144Network 无向图求割点Tarjan

n个点,组成一个无向图,求这个图中割点的数量.模板题. 只是这道题在输入数据的时候有点麻烦,如样例中,第一组数据有五个点,5 1 2 3 4 表示5这个点与1 2 3 4 点相连.其中这个图的割点只是5这个点.第二组数据6个点,2 与1 3 5相连,5与2 4 6相连,其中2点与5点都是割点. 有两类节点可以成为割点: 对根节点u,若其有两棵或两棵以上的子树,则该根结点u为割点: 对非叶子节点u(非根节点),若其子树的节点均没有指向u的祖先节点的回边,说明删除u之后,根结点与u的子树的节点不再连

UVA315 (无向图求割点)

题目大意:给定一个无向图,问共存在多少个割点.(割点:去掉此点后此图会断开连接)割点有两种存在:一种是第一次搜索的根节点,若其子节点数超过两个,则此点去掉后图会 断开连接,因此此点为割点:或者此点为搜索树的子节点,若其子节点的最早达到时间状态比其自身要晚,则说明此点不得不经过,并以此来更新其子节点,故其也是割点. 详见代码. #include <stdio.h> #include <algorithm> #include <vector> #include <st

无向图求割点 UVA 315

***割点概念:去掉一个点后图不连通,改点就为割点 割点满足的条件: 一个顶点u是割点,当且仅当满足(1)或(2) (1)一个顶点u是割点,当且仅当满足(1)或(2). (2) u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的父亲),使得 dfn(u)<=low(v). 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=122091#problem/B*** #include<cstdio>