POJ 1698 (multi-match for binary graphs)

Source: Internet
Author: User

Reprint: Http://www.cppblog.com/MatoNo1/archive/2011/03/26/142766.aspx

  We know that in a graph, the maximum number of matches for a single edge of each point is the largest matching problem of a binary graph. However, there is a situation where each point can match multiple edges, but there is an upper limit, which is assumed to be L. That is, the maximum point I can be associated with the Li Bar.

Binary graph multiple maximum match:

1. Create a source point S and a meeting point T.

The 2.S points to the X vertex, and the capacity is the L value of the point within X. The y vertex points to T, and the capacity is the L value of the point within Y.

3. Each side of the original image still exists in the new diagram, with a capacity of 1.

Then the maximum flow of S to T is the multiple maximum match.

For example POJ1698:

1#include <cstdio>2#include <cstring>3#include <queue>4 #define_CLR (x, y) memset (x, y, sizeof (x))5 #defineMin (x, y) (x < y x:y)6 #defineMax (x, y) (x > Y x:y)7 #defineINF 0x3f3f3f3f8 #defineN 4009 using namespacestd;Ten  One intEdge[n][n], dist[n]; A intT, S, Sum, N; - BOOLUsed[n]; -  the BOOLBFS () - { -_CLR (Dist,-1); -queue<int>Q; +Dist[s] =0; - Q.push (S); +      while(!q.empty ()) A     { at         intU =Q.front (); - Q.pop (); -          for(intv=0; v<=t; v++) -         { -             if(Edge[u][v] && dist[v]<0) -             { inDIST[V] = Dist[u] +1; - Q.push (v); to             } +         } -     } the     returnDist[t]>0?1:0; * } $ Panax Notoginseng intDfsintUintAlpha) - { the     intA; +     if(u==t)returnAlpha; A      for(intI=0; i<=t; i++) the     { +         if(Edge[u][i] && dist[i]==dist[u]+1&& (a=DFS (i, Min (Alpha, Edge[u][i] )))) -         { $Edge[u][i]-=A; $Edge[i][u] + =A; -             returnA; -         } the     } -Dist[u] =-1;Wuyi     return 0; the } - voiddinic () Wu { -     intans=0, a=0; About      while(BFS ()) $          while(A=dfs (0, INF)) ans + =A; -printf ("%s\n", Ans==sum?"Yes":"No"); - } -  A intMain () + { the     intK, week[Ten]; -scanf"%d", &K); $      while(k--) the     { the         intDay =0, D, W; thescanf"%d", &n); theSum =0, s=0; -_CLR (Week,0); in_CLR (Edge,0); the          for(intI=1; i<=n; i++)//1--n between the movies, N+1---t represents the number of days! the         { About              for(inti1=0; i1<7; i1++) scanf ("%d", week+i1); thescanf"%d%d", &d, &W); theDay =Max (Day, W); theEdge[s][i] = D;//The source points to each festival point x to connect a weight to the number of days required to take the movie. +Sum + =D; -  the              for(intj=0; j<w; J + +)//within a W week to complete.Bayi             { the                  for(intk=0; k<7; k++) the                     if(Week[k]) -edge[i][n+j*7+k+1] =1;//Part I movies can be taken at week K within W week. -             } theT = day*7+n+1; the              for(inti=n+1; i<t; i++) theEDGE[I][T] =1; the         } - dinic (); the     } the     return 0; the}

POJ 1698 (multi-match for binary graphs)

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.