強聯通tarjan的一些黑科技以及隨想

來源:互聯網
上載者:User

標籤:cli   sdn   UNC   ems   rom   soft   ==   event   else   

我很不要臉的直接安利ATP大佬的blog了(原諒我大yz風氣習慣把女生叫做大佬)

放置一些ban(突然想到某農藥)子。

int z,dfn[110000],low[110000];int top,sta[110000];bool v[110000];int cnt,belong[110000];void strong_unicom(int x){    dfn[x]=low[x]++z;    sta[++top]=x;v[x]=true;    for(int k=last[x];k;k=a[k].next)    {        int y=a[k].y;        if(dfn[y]==0)        {            strong_unicom(y);            low[x]=min(low[x],low[y]);        }        else        {            if(v[y]==true)                low[x]=min(low[x],dfn[y]);        }    }    if(dfn[x]==low[x])    {        int i;cnt++;        do        {            i=sta[top];top--;            v[i]=false;            belong[i]=cnt;        }while(i!=x);    }}//----------------function--------------------    z=top=cnt=0;    memset(dfn,0,sizeof(dfn));    memset(low,0,sizeof(low));    memset(v,false,sizeof(v));    for(int i=1;i<=n;i++)        if(dfn[i]==0)strong_unicom(i);//------------------main------------------- 
基本的強聯通(擺著也是擺著)

 

曾經大家都很糾結一個問題
low[x]=min(low[x],dfn[y]);換成low[x]=min(low[x],low[y]);
也可以AC,現在明白了,是強調割點的意義。

int z,dfn[110000],low[110000],cut[110000];void findcut(int x){    dfn[x]=low[x]=++z;    for(int k=last[x];k;k=a[k].next)    {        int y=a[k].y;        if(dfn[y]==0)        {            findcut(y);            low[x]=min(low[x],low[y]);            if(low[y]>=dfn[x])cut[x]++;        }        else low[x]=min(low[x],dfn[y]);    }}//----------------function--------------------    z=0;    memset(dfn,0,sizeof(dfn));    memset(low,0,sizeof(low));    memset(cut,0,sizeof(cut));    for(int i=1;i<=n;i++)        if(dfn[i]==0)findcut(i);        else cut[i]++;//------------------main------------------- 
求一個點連向的割點個數(bzoj2730礦場搭建)

 

強聯通tarjan的一些黑科技以及隨想

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.