zoukankan      html  css  js  c++  java
  • 无向连通图求割点模板

    无向连通图的DFS树中有两类节点可以成为割点:

    1. 对根节点u,若其有两棵或两棵以上的子树,则该根结点u为割点;
    2. 对非叶子节点u(非根节点),若其子树的节点均没有指向u的祖先节点的回边,说明删除u之后,根结点与u的子树的节点不再连通,则节点u为割点。

    const int MAXN = 205;
    
    bool map[MAXN][MAXN];
    int DFN[MAXN];//记录节点第一次被访问时的时间
    int LOW[MAXN];//记录节点与节点的子树节点中最早的步数 
    bool book[MAXN];
    int timee; 
    int N;
    int sum;
    
    void Tarjan(int x,int pre){
        DFN[x] = LOW[x] = ++timee;
        int son = 0;
        for(int i=1 ; i<=N ; ++i){
            if(map[x][i] == false || i == pre)continue;
            if(!DFN[i]){
            	++son;
                Tarjan(i,x);
                if(LOW[i]<LOW[x]){
                    LOW[x] = LOW[i];
                }
                if(x != pre && LOW[i]>=DFN[x])book[x] = true;
            }
            else if(LOW[x]>DFN[i]){
                LOW[x] = DFN[i];
            }
        }
        if(x == pre && son>1)book[x] = true;
    }
    
    void init(){
        memset(map,false,sizeof(map));
        memset(book,false,sizeof(book));
        memset(DFN,0,sizeof(DFN));
        memset(LOW,0,sizeof(LOW));
        timee = 0;
        sum = 0;
    }

  • 相关阅读:
    spring MVC配置详解
    使用JDBC连接各种数据库
    Linux Shell常用shell命令
    IOS返回go(-1)
    NFS客户端挂载
    oracle常用函数
    支付宝手机网站支付流程(Node实现)
    SQL中的case when then else end用法
    mysql
    socket
  • 原文地址:https://www.cnblogs.com/vocaloid01/p/9514076.html
Copyright © 2011-2022 走看看