tarjan-无向图(求割点)

一、基本概念

1、割点:无向连通图中,如果删除某点后,图变成不连通,则称改点为割点。

2、桥:无向连通图中,如果去掉某条边后,整张无向图会分成两部分(即整张图不连通),这样的一条边成为桥。

3、点双连通分量:无割点的极大连通子图

        任意两点间都有?至少两条不不经过相同边的路径

4、边双连通分量:无割边的极大连通子图

        任意两点间都有?至少两条(除起点和终点外)不不经过相同点的路径

二、tarjan求割点

1)当前节点为树根时,成为割点的条件是“要有多于一个子树”(如果只有一棵子树,去掉这个点也没有影响,如果有两颗子树,去掉这个点,两颗子树就不连通了)

2)当前节点不是树根的时候,条件是“low [ v ] >= dfn [ u ] ”,也就是在u之后遍历的点,能够向上翻,最多到u。(如果能翻到u的上方,那就有环了,去掉u之后,图仍然连通。)所以,保证v向上翻最多到u才可以

洛谷板子题

#include<cstdio>
#include<algorithm>
using namespace std;

inline int read()
{
    int sum = 0,p = 1;
    char ch = getchar();
    while(ch < ‘0‘ || ch > ‘9‘)
    {
        if(ch == ‘-‘)
            p = -1;
        ch = getchar();
    }
    while(ch >= ‘0‘ && ch <= ‘9‘)
    {
        (sum *= 10) += ch - ‘0‘;
        ch = getchar();
    }
    return sum * p;
}

const int maxn = 20005,maxm = 100005;
int n,m,tot;
int dfn[maxn],low[maxn],tim;
int cnt,head[maxn];
struct edge
{
    int nxt,to;
}e[maxm * 2];
bool mrk[maxn];

void add(int x,int y)
{
    e[++cnt].nxt = head[x];
    e[cnt].to = y;
    head[x] = cnt;
}

void tarjan(int u,int fa)
{
    dfn[u] = low[u] = ++tim;
    int child = 0;
    for(int i = head[u];i;i = e[i].nxt)
    {
        int v = e[i].to;
        if(!dfn[v])
        {
            tarjan(v,fa);
            low[u] = min(low[u],low[v]);
            if(low[v] >= dfn[u] && u != fa)
                mrk[u] = true;
            if(u == fa)
                child++;
        }
        low[u] = min(low[u],dfn[v]);
    }
    if(child >= 2 && u == fa)
        mrk[u] = true;
}

int main()
{
    n = read(),m = read();
    for(int i = 1;i <= m;i++)
    {
        int x = read(),y = read();
        add(x,y);
        add(y,x);
    }
    for(int i = 1;i <= n;i++)
        if(!dfn[i])
            tarjan(i,i);
    for(int i = 1;i <= n;i++)
        if(mrk[i])
            tot++;
    printf("%d\n",tot);
    for(int i = 1;i <= n;i++)
        if(mrk[i])
            printf("%d ",i);
    return 0;
}

原文地址:https://www.cnblogs.com/darlingroot/p/11221478.html

时间: 2024-07-31 20:41:38

tarjan-无向图(求割点)的相关文章

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

(转)Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)

本文转载自:http://hi.baidu.com/lydrainbowcat/item/f8a5ac223e092b52c28d591c 作者提示:在阅读本文之前,请确保您已经理解并掌握了基本的Tarjan算法,不会的请到http://hi.baidu.com/lydrainbowcat/blog/item/42a6862489c98820c89559f3.html阅读.   基本概念:   1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如

Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)【转】【修改】

基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成多个连通块,就称这个点集为割点集合. 3.点连通度:最小割点集合中的顶点数. 4.割边(桥):删掉它之后,图必然会分裂为两个或两个以上的子图. 5.割边集合:如果有一个边集合,删除这个边集合以后,原图变成多个连通块,就称这个点集为割边集合. 6.边连通度:一个图的边连通度的定义为,最小割边集合中的边数.

无向图求割点 UVA 315 Network

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

tarjan算法求割点cojs 8

tarjan求割点:cojs 8. 备用交换机 ★★   输入文件:gd.in   输出文件:gd.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] n个城市之间有通讯网络,每个城市都有通讯交换机,直接或间接与其它城市连接.因电子设备容易损坏,需给通讯点配备备用交换机.但备用交换机数量有限,不能全部配备,只能给部分重要城市配置.于是规定:如果某个城市由于交换机损坏,不仅本城市通讯中断,还造成其它城市通讯中断,则配备备用交换机.请你根据城市线路情况,计算需配备备用交换

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

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的子树的节点不再连