POJ 1966 Cable TV Network

Source: Internet
Author: User

Description:

Given an undirected graph, ask at least how many points are removed to make the diagram disconnected. Points n≤50

Idea: First fix a point s, then enumerate another point T, and then ask for at least a few points to cut off to make two point not connected

Natural contact to the smallest cut, but the smallest cut is cut edge, cut point? As long as each point is split into two points, cutting a point is equivalent to disconnecting the edge in the middle of the two points it splits in the network.

So the Benquan in the original graph is set to positive infinity, then the Benquan between each point pair is set to 1, then you can use the minimum cut to write

#include <iostream>#include<cstring>#include<queue>#include<cstdio>using namespacestd;Const intN = the;Const intM =10010;Const intINF =1e9;intHead[n],now;structedges{intTo,next,w;} Edge[m<<1];voidAddintUintVintW) {Edge[++now] = {v,head[u],w}; Head[u] =Now ;}intN,m,s,t,dep[n],ans;voidinit () {memset (Edge,0,sizeof(Edge)); now =1; memset (Head,0,sizeof(head)); memset (DEP,0,sizeof(DEP));}intDinic (intXintflow) {    if(x = = t)returnflow; intRest =flow, K;  for(inti = head[x]; I i =Edge[i].next) {        intv =edge[i].to; if(EDGE[I].W && dep[v] = = Dep[x] +1) {k=Dinic (V,min (rest, EDGE[I].W)); if(!k) Dep[v] =0; EDGE[I].W-=K; Edge[i^1].W + =K; Rest-=K; }    }    returnFlow-rest;}BOOLBFs () {memset (DEP,0,sizeof(DEP)); Queue<int>Q; Q.push (s); Dep[s]=1;  while(!Q.empty ()) {        intx =Q.front (); Q.pop ();  for(inti = head[x]; I i =Edge[i].next) {            intv =edge[i].to; if(EDGE[I].W &&!)Dep[v])                {Q.push (v); DEP[V]= Dep[x] +1; if(v = = t)return 1; }        }    }    return 0;}structinput{intx, y;} INP[M];intMain () { while(SCANF ("%d%d", &n,&m)! =EOF) {ans=INF; intx, y;  for(inti =1; I <= m; i++) {scanf ("(%d,%d)",&x,&y); X+ +, y++; Inp[i]={x, y};//Add (X,y+n,inf); add (y+n,x,0);        }        if(n = =1) {puts ("1"); Continue; } s=1;  for(t =2; t <= N; t++) {//Enumerate an end pointinit ();  for(inti =1; I <= m; i++) {Add (Inp[i].y+ n,inp[i].x, INF);//Split EdgeAdd (Inp[i].x,inp[i].y + N,0); Add (inp[i].x+n,inp[i].y, INF); Add (inp[i].y,inp[i].x+ N,0); }            intx, y;  for(inti =1; I <= N; i++)              if(I! = s && i! =t) Add (i,i+n,1), add (I+n,i,0);//set the Benquan between the split points to 1            intTMP =0, Maxflow =0; S+=N;  while(BFS ())//maximum flow minimum cut               while(TMP = Dinic (s,inf)) Maxflow + =tmp; Ans=min (ans,maxflow); S-=N; }        if(ans = = INF) printf ("%d\n", N); Elseprintf"%d\n", ans); }    return 0;}

POJ 1966 Cable TV Network

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.