poj 1966 Cable TV Network

來源:互聯網
上載者:User

標籤:cstring   容量   ios   min   ini   size   ret   頂點   using   

給出一個無向圖,求該圖的點連通度。

點連通度:最小割點集合中的頂點數。

0<=n=50.

最小割。

邊連通度很好求,只需要隨便固定源點枚舉匯點求最小割取min即可。

點連通度採用點邊轉化的思想,將每個點拆點,入點與出點連邊將點上的資訊反映在邊上。

每個點的入點向出點連一條容量為1的邊。

每條邊拆成兩條有向邊,對於有向邊(u,v)從u的出點向v的入點連一條容量為正無窮的邊。

n2枚舉源點和匯點,最小割取min即為答案。

割掉入出點間的邊相當於刪掉該點。真正的邊不能刪掉,設成正無窮防割。

點連通度不能固定源點枚舉匯點,因為源匯兩點預設不在最小割點集合中,所以必須枚舉源匯,

 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #include<queue> 6 using namespace std; 7 const int dian=105; 8 const int bian=20005; 9 const int INF=0x3f3f3f3f;10 const int inf=100000;11 int h[dian],ver[bian],val[bian],nxt[bian],ch[dian],cr[dian];12 int n,m,tot,aa,bb,ans;13 int S,T;14 void add(int a,int b,int c){15     tot++;ver[tot]=b;val[tot]=c;nxt[tot]=h[a];h[a]=tot;16     tot++;ver[tot]=a;val[tot]=0;nxt[tot]=h[b];h[b]=tot;17 }18 bool tell(){19     memset(ch,-1,sizeof(ch));20     queue<int>q;21     q.push(S);22     ch[S]=0;23     while(!q.empty()){24         int t=q.front();25         q.pop();26         for(int i=h[t];i;i=nxt[i])27             if(ch[ver[i]]==-1&&val[i]){28                 ch[ver[i]]=ch[t]+1;29                 q.push(ver[i]);30             }31     }32     return ch[T]!=-1;33 }34 int zeng(int a,int b){35     if(a==T)36         return b;37     int r=0;38     for(int i=cr[a];i&&b>r;i=nxt[i])39         if(ch[ver[i]]==ch[a]+1&&val[i]){40             int t=zeng(ver[i],min(b-r,val[i]));41             val[i]-=t,r+=t,val[i^1]+=t;42             if(val[i])43                 cr[a]=i;44         }45     if(!r)46         ch[a]=-1;47     return r;48 }49 int dinic(){50     int r=0,t;51     while(tell()){52         for(int i=1;i<=n+n;i++)53             cr[i]=h[i];54         while(t=zeng(S,INF))55             r+=t;56     }57     return r;58 }59 int main(){60     while(scanf("%d%d",&n,&m)!=EOF){61         memset(h,0,sizeof(h));62         memset(nxt,0,sizeof(nxt));63         tot=1;64         ans=INF;65         for(int i=1;i<=n;i++)66             add(i,i+n,1);67         for(int i=1;i<=m;i++){68             scanf(" (%d,%d)",&aa,&bb);69             add(aa+n+1,bb+1,inf);70             add(bb+n+1,aa+1,inf);71         }72         for(int i=1;i<=n;i++)73             for(int j=1;j<=n;j++){74                 if(i==j)75                     continue;76                 S=i+n,T=j;77                 ans=min(ans,dinic());78                 for(int k=2;k<=tot;k+=2){79                     val[k]+=val[k^1];80                     val[k^1]=0;81                 }82             }83         if(ans>=inf)84             ans=n;85         printf("%d\n",ans);86     }87     return 0;88 }

 

poj 1966 Cable TV Network

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.