51Nod 2006 pilot pair (binary Max match)-Hungarian algorithm

Source: Internet
Author: User

2006 Pilot pairing (two-dimensional maximum match) topic Source: Network Flow 24 Baseline time limit: 1 seconds space limit: 131072 KB score: 0 Difficulty: Basic problem collection concern

During the Second World War, the Royal Air Force recruited a large number of foreign pilots from the occupied countries. Each aircraft dispatched by the Royal Air Force needs to be equipped with 2 pilots, including 1 British pilots and 1 foreign pilots, who can match the skill and language of the craft. Among the many pilots, each of the foreign pilots was able to work well with several other British pilots. How to choose a paired flight pilot to make the most out of one flight. For a given foreign pilot and British pilots, try to design an algorithm to find out the best pilot matching scheme, so that the Royal Air Force can send the most aircraft. For a given foreign pilot with a British pilot, programming to find the best pilot matching scheme, so that the Royal Air Force can send the most aircraft.

Input
The 1th line has 2 positive integers m and N. n is the total number of pilots of the RAF (N<100); M is the number of foreign pilots. The foreign pilot is numbered 1~m; The British pilot number is m+1~n. Next, there are 2 positive integers i and j for each line, indicating that the foreign pilot I can match the British pilot J. The inputs end with 2-1.
Output
Line 1th is the best pilot matching program. The maximum number of aircraft to be dispatched at a time is M. If the optimal pilot pairing scheme is not present, then output ' no solution! '.
Input example
5 101 71 82 62 92 103 73 84 74 85 10-1-1
Output example
4

#include <cstdio>#include<iostream>#include<vector>#include<cstring>using namespacestd; intans; Vector<int> h[ +]; intn,m; intvis[12000]; intp[10000]; BOOLDfsintx) { for(intj=0; J)      {          intu=H[x][j]; if(!Vis[u]) {Vis[u]=1; if(!p[u]| |DFS (P[u])) {P[u]=x; return true; }      }      }      return false; }  intMain () {Ios::sync_with_stdio (0); intu,v; CIN>>m>>N;  while(cin>>u>>v) {if(u==-1) Break;      H[u].push_back (v); }       for(intI=1; i<=n;i++) {memset (Vis,0,sizeof(VIS)); if(Dfs (i)) ans++; }      if(ANS) cout<<ans<<Endl; Elsecout<<"No solution!\n"; return 0; }  

51Nod 2006 pilot pair (binary Max match)-Hungarian algorithm

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.