首页 > 其他 > 详细

连通分量相关代码

时间:2021-01-03 10:51:18      阅读:18      评论:0      收藏:0      [点我收藏+]
// 割边
void tar(int x,int in_e)
{
  dfn[x] = low[x] = ++cnt;
  for(int i=hd[0][x],y=vr[i]; i; i=nt[i],y=vr[i])
    if(!dfn[y])
    {
      tar(y,i);
      low[x] = min(low[x],low[y]);
      
      if(low[y]>dfn[x]) bri[i]=bri[i^1]=true;
    } else
        if(i != (in_e^1)) low[x]=min(low[x],dfn[y]);
}

//割点
void tar(int x)
{
  dfn[x] = low[x] = ++cnt;
  if(rt==x && !hd[x])
  {
    dcc[++dcnt].clear();
    dcc[dcnt].push_back(x);
    return;
  }
  sta[++tp] = x;
  for(int i=hd[x],y=vr[i]; i; i=nt[i],y=vr[i])
    if(!dfn[y])
    {
      tar(y);
      low[x] = min(low[x],low[y]);
      
      if(low[y]>=dfn[x])
      {
        ++flg;
        if(flg>1 || x!=rt) cut[x]=true;

        dcc[++dcnt].clear();
        int z;
        do{
          z=sta[tp--];
          dcc[dcnt].push_back(z);
        } while(z!=y);
        dcc[dcnt].push_back(x);
      }
    }
    else low[x] = min(low[x],dfn[y]);
}

连通分量相关代码

原文:https://www.cnblogs.com/tztqwq/p/14224784.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!