POJ 1966 Cable TV Network vertex connectivity

Source: Internet
Author: User

Topic links

to a graph, N points m edge, ask at least how many points removed can make the diagram no longer connected.
Arbitrarily specify a point as the source point, enumerate the other points as the meeting point, run the network flow, to find the smallest case. If the last ans is an inf, the description is a full graph, then the result is N.

1#include <iostream>2#include <vector>3#include <cstdio>4#include <cstring>5#include <algorithm>6#include <cmath>7#include <map>8#include <Set>9#include <string>Ten#include <queue> One using namespacestd; A #definePB (x) push_back (x) - #definell Long Long - #defineMK (x, y) make_pair (x, y) the #defineLson L, M, rt<<1 - #defineMem (a) memset (a, 0, sizeof (a)) - #defineRson m+1, R, rt<<1|1 - #defineMem1 (a) memset (a,-1, sizeof (a)) + #defineMEM2 (a) memset (a, 0x3f, sizeof (a)) - #defineRep (I, A, n) for (int i = A; i<n; i++) + #defineull unsigned long Long Atypedef pair<int,int>PLL; at Const DoublePI = ACOs (-1.0); - Const DoubleEPS = 1e-8; - Const intMoD = 1e9+7; - Const intINF =1061109567; - Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} }; - Const intMAXN = 4e4+5; in intq[maxn*2], head[maxn*2], dis[maxn/Ten], S, T, NUM, edge[2500][2]; - structnode to { +     intto, Nextt, C; - node () {} theNodeintTo,intNextt,intc): To, Nextt (NEXTT), C (c) {} *}e[maxn*2]; $ voidinit () {Panax Notoginsengnum =0; - mem1 (head); the } + voidAddintUintVintc) { AE[num] = node (V, Head[u], c); Head[u] = num++; theE[num] = node (u, Head[v],0); HEAD[V] = num++; + } - intBFs () { $ mem (dis); $Dis[s] =1; -     intSt =0, ed =0; -q[ed++] =s; the      while(st<ed) { -         intU = q[st++];Wuyi          for(inti = Head[u]; ~i; i =e[i].nextt) { the             intv =e[i].to; -             if(!dis[v]&&e[i].c) { WuDIS[V] = dis[u]+1; -                 if(v = =t) About                     return 1; $q[ed++] =v; -             } -         } -     } A     return 0; + } the intDfsintUintlimit) { -     if(U = =t) { $         returnlimit; the     } the     intCost =0; the      for(inti = Head[u]; ~i; i =e[i].nextt) { the         intv =e[i].to; -         if(E[i].c&&dis[v] = = dis[u]+1) { in             intTMP = DFS (V, min (limit-Cost , e[i].c)); the             if(tmp>0) { theE[I].C-=tmp; Aboute[i^1].C + =tmp; theCost + =tmp; the                 if(Cost = =limit) the                      Break; +}Else { -DIS[V] =-1; the             }Bayi         } the     } the     returnCost ; - } - intDinic () { the     intAns =0; the      while(BFS ()) { theAns + =DFS (s, INF); the     } -     returnans; the } the intMain () the {94     intN, m, x, y; the      while(~SCANF ("%d%d", &n, &m)) { the          for(inti =0; i<m; i++) { thescanf"(%d,%d)", &edge[i][0], &edge[i][1]);98         } Abouts =N; -         intAns =inf;101          for(inti =1; i<n; i++) {102t =i;103 init ();104              for(intj =0; j<m; J + +) { the                 intx = edge[j][0];106                 inty = edge[j][1];107Add (x+N, y, INF);108Add (y+N, x, INF);109             } the              for(intj =0; j<n; J + +)111Add (J, J+n,1); theAns =min (ans, dinic ());113         } the         if(ans = =inf) theAns =N; thecout<<ans<<Endl;117     }118     return 0;119}

POJ 1966 Cable TV Network vertex connectivity

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.