Hungarian algorithm cojs.tk paired with pilot

Source: Internet
Author: User

cojs.tk Match pilot ★★☆ input file: flyer.inOutput 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 Ten
3 7
4 8
5 9
Output file name:Flyer.out4
1#include <vector>2#include <iostream>3 using namespacestd;4#include <cstdio>5#include <cstring>6 #defineN 1107 BOOLvisit[n]={false};8 intn,n1;9 structedge{Ten     intV,last; One }; A intm=-1, head[n],link[n]; -Vector<edge>Edge; - voidAdd_edge (intUintv) the { - Edge E; -e.v=v; -e.last=Head[u]; +head[u]=++m; - Edge.push_back (e); + } A voidinput () at { -scanf"%d%d",&n,&N1); -     intu,v; -      while(SCANF ("%d%d", &u,&v) = =2) -     { - Add_edge (u,v); in     } - } to BOOLXylfind (intk) + { -      for(intl=head[k];l!=-1; l=edge[l].last) the     { *         if(!VISIT[EDGE[L].V]) $         {Panax Notoginsengvisit[edge[l].v]=true; -             if(! link[edge[l].v]| |Xylfind (LINK[EDGE[L].V])) the             { +link[edge[l].v]=K; A                 return true; the             } +         } -     } $     return false; $ } - intMain () - { theFreopen ("flyer.in","R", stdin); -Freopen ("Flyer.out","W", stdout);Wuyimemset (head,-1,sizeof(head)); the input (); -     intans=0; Wu      for(intI=1; i<=n1;++i) -     { Aboutmemset (Visit,false,sizeof(visit)); $         if(Xylfind (i)) ans++; -     } -printf"%d\n", ans); - fclose (stdin); A fclose (stdout); +     return 0; the}

Hungarian algorithm cojs.tk paired with pilot

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.