CODEVS1232 Pilot Pairing scheme problem "binary graph maximum matching"

Source: Internet
Author: User

Codevs on the special judge seems to hang, so he went to cogs handed over http://cojs.tk/cogs/problem/problem.php?pid=14

14. [Network Flow 24 questions] with pilots

★★☆ input file: flyer.in output file: flyer.out Simple comparison
Time limit: 1 s memory limit: MB

"Problem description"The Flight brigade has a number of pilots from all over the world who specialize in one type of aircraft, each of which has two drivers and requires a pilot and a co-pilot. For a variety of reasons, such as co-ordination, some pilots cannot fly on the same plane and ask how to match the driver to make the most of the flight.
, assuming that there are 10 drivers, the V1,V2,...,V10 represents up to 10 drivers, of which V1,V2,V3,V4,V5 is the pilot, and V6,V7,V8,V9,V10 is the co-pilot. If a pilot and a co-pilot can fly on the same plane, on behalf of both of them a line between the two, two people can not fly with the aircraft, it is not connected. For example, V1 and V7 can fly on the same plane, while V1 and V8 do not. Please match the pilot to make the most of the aircraft sailing. Note: Because of the strict division of the driving work, two or two copilot pilots can not fly on the plane.
The input format input file has several lines
The first line, two integers n and N1, indicates a total of n pilots (2<=N<=100), including N1 pilots.
There are several lines below, each with 2 numbers, A, B. Indicates that both driver A and copilot B can fly on the same machine. Note: The pilot's number is before the driver's number is less than the pilot's number. Output format output file has one line
The first line, 1 integers, indicates the maximum number of aircraft to take off. Input Output Sample input file name: Flyer.in10 5
1 7
2 6
2 10
3 7
4 8
5 9
Output file name: flyer.out bare binary graph maximum matching super source S to positive driver with a capacity of 1 pairs of drivers to the Super sink T edge capacity of 1 corresponding to the driver and co-pilot side capacity of 1 and then run Dinic
#include <cstdio>#defineINF 214748263#include<iostream>#include<algorithm>#include<queue>#defineN 500#include<cstring>using namespacestd;intdis[ -],n,m,ans,tot=1, A,b,c,i,head[n],nn;structedge{intTo,next,w;} E[n<<1];inlinevoidInsintUintVintW) {e[++tot].w=w; E[tot].to=v; E[tot].next=head[u]; head[u]=tot;}intBFs () {memset (DIS,-1,sizeof(dis)); dis[1]=0; queue<int>Q; Q.push (1);  while(!Q.empty ()) {              intnow=Q.front (); Q.pop ();  for(intk=head[now];k;k=e[k].next)if(dis[e[k].to]<0&& e[k].w>0) {dis[e[k].to]=dis[now]+1; Q.push (e[k].to); }       }        if(dis[m]>0)return 1;Else return 0;}intFindintXintLow ) {    if(x==m)returnLowintA;  for(intk=head[x];k;k=e[k].next)if(e[k].w>0&& dis[e[k].to]==dis[x]+1&& (a=Find (E[k].to,min (LOW,E[K].W)))) {E[K].W-=a; e[k^1].w+=a;returnA; }      return 0;}intMain () {Freopen ("flyer.in","R", stdin); Freopen ("Flyer.out","W", stdout); scanf ("%d%d", &nn,&n);  Nn-=n; m=1+n+nn+1;  for(i=1; i<=n;i++) Ins (1,1+i,1), INS (i+1,1,0);  for(i=1; i<=nn;i++) Ins (1+n+i,m,1), INS (M,1+n+i,0);  while(SCANF ("%d%d", &a,&b)! =EOF) {           ++a; ++b; Ins (A, B,1); Ins (B,a,0); }      while(BFS ()) { while(Tot=find (1, INF)) ans+=tot; } printf ("%d", ans); fclose (stdin); Fclose (stdout);}
View Code

CODEVS1232 Pilot Pairing scheme problem "binary graph maximum matching"

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.