UVa1660 Cable TV Network (undirected graph, point connectivity, maximum flow)

Source: Internet
Author: User

Links: http://bak3.vjudge.net/problem/UVA-1660

Analysis: This blog is very detailed. Http://www.cnblogs.com/xcw0754/p/4662429.html

1#include <cstdio>2#include <queue>3#include <cstring>4#include <vector>5 using namespacestd;6 7 Const intMAXN = -+5;8 Const intINF =0x3f3f3f3f;9 Ten structEdge { One     int  from, to, cap, flow; AEdge (intUintVintCintf): from(U), to (v), Cap (c), Flow (f) {} - }; -  the structEdmondskarp { -     intN, M; -Vector<edge>edges; -vector<int>G[MAXN]; +     intA[MAXN]; -     intP[MAXN]; +  A     voidInitintN) { at          for(inti =0; I < n; i++) g[i].clear (); - edges.clear (); -     } -  -     voidAddedge (int  from,intTo,intcap) { -Edges.push_back (Edge ( from, to, Cap,0)); inEdges.push_back (Edge to, from,0,0)); -m =edges.size (); tog[ from].push_back (M-2); +G[to].push_back (M-1); -     } the  *     intMaxflow (intSintt) { $         intFlow =0;Panax Notoginseng          for (;;) { -Memset (A,0,sizeof(a)); thequeue<int>Q; + Q.push (s); AA[s] =INF; the              while(!Q.empty ()) { +                 intx =Q.front (); Q.pop (); -                  for(inti =0; I < g[x].size (); i++) { $edge& e =Edges[g[x][i]]; $                     if(!a[e.to] && e.cap >e.flow) { -P[e.to] =G[x][i]; -A[e.to] = min (a[x], E.cap-e.flow); the Q.push (e.to); -                     }Wuyi                 } the                 if(A[t]) Break; -             } Wu             if(!a[t]) Break; -              for(intu = t; U! = S; U = edges[p[u]]. from) { AboutEdges[p[u]].flow + =A[t]; $Edges[p[u] ^1].flow-=A[t]; -             } -Flow + =A[t]; -         } A         returnflow; +     } the }; -  $ Edmondskarp G; theVector<edge>Bak; the  the intMain () { the     intN, M; -      while(SCANF ("%d%d", &n, &m) = =2) { inG.init (n *2); the          for(inti =0; I < n; i++) G.addedge (i, i + N,1); the          for(inti =0, u, v; I < m; i++) { Aboutscanf"(%d,%d)", &u, &v); theG.addedge (U +N, v, INF); theG.addedge (v +N, u, INF); the         } +         ints = N, flow = n; Bak =g.edges; -          for(inti =1; I < n; i++) { theG.edges =Bak;BayiFlow =min (Flow, g.maxflow (S, i)); the         } theprintf"%d\n", flow); -     } -     return 0; the}

UVa1660 Cable TV Network (undirected graph, point connectivity, maximum flow)

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.