Cable TV Network vertex connectivity (maximum flow algorithm)

Source: Internet
Author: User

Cable TV Network

Abstract: Give a graph with n points vertex, give M edge. Find the point of connectivity K

Algorithm: Each vertex v is split into V ' V ', and V '-->v ' has a capacity of 1.    For edges in the original (u,v) edge u '--->v ' V '-->u '. P (u,v) for each pair of points, with u as source and V as meeting point.

We just need to fix one vertex and enumerate the other sinks.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <string>7#include <vector>8#include <Set>9#include <map>Ten#include <stack> One#include <queue> A#include <sstream> -#include <iomanip> - using namespacestd; thetypedefLong LongLL; - Const intINF =0x4fffffff; - Const DoubleEXP = 1e-5; - Const intMS = the; + Const intSIZE =100005; -  + //maximum flow algorithm for vertex connectivity of undirected graphs A  at intCap[ms][ms]; - intFLOW[MS][MS];//to disassemble struct C F into two arrays - intQue[ms]; - intPre[ms]; - intAlpha[ms]; - intQs,qe,nodes; in intn,m; -  to intMax_flow (intSource,intsink) + { -memset (Flow,0,sizeof(flow));//0 Stream starts to increase traffic the       intres=0; *        while(1) $       {Panax NotoginsengQs=qe=0; -que[qe++]=Source; thememset (pre,-1,sizeof(pre));//the pre can play the role of flag at the same time +memset (alpha,-1,sizeof(Alpha)); Aalpha[source]=INF; thepre[source]=-2;//-2 end tag, while avoiding-1, indicating no access +              while(qs<QE) -             { $                   intu=que[qs++]; $                    for(intv=0; v<nodes;v++) -                   { -                         if(pre[v]==-1&&flow[u][v]<Cap[u][v]) the                         { -que[qe++]=v;Wuyipre[v]=u; theAlpha[v]=min (alpha[u],cap[u][v]-flow[u][v]); -                         } Wu                   } -                   if(pre[sink]!=-1) About                   { $                         intk=sink; -                          while(pre[k]>=0) -                         { -flow[pre[k]][k]+=Alpha[sink]; Aflow[k][pre[k]]=-Flow[pre[k]][k]; +k=Pre[k]; the                         } -                          Break; $                   } the             } the             if(pre[sink]==-1)//There is no augmented path the                   returnRes; the             Else -res+=Alpha[sink]; in       } the } the  About intMain () the { the        while(SCANF ("%d%d", &n,&m)! =EOF) the       { +             inta,b,ans=INF; -memset (Cap,0,sizeof(CAP)); thenodes=2*N;Bayi              for(intI=0; i<n;i++) thecap[i][i+n]=1; the              for(intI=0; i<m;i++) -             { -scanf"(%d,%d)",&a,&b); thecap[a+n][b]=cap[b+n][a]=INF; the             } the              for(intv=1; v<n;v++) the             { -ans=min (Ans,max_flow (n,v)); the             } the             if(ans==INF) theans=N;94printf"%d\n", ans); the       } the       return 0; the}

Cable TV Network vertex connectivity (maximum flow algorithm)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.