Describe
Http://cojs.tk/cogs/problem/problem.php?pid=14
There are pilots and co-pilots who give each pilot the pilots they can take off with. A plane must be a pair, the maximum number of aircraft can fly.
Analysis
Bare Binary graph matching ...
Please call me the little prince of water problem ...
1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intmaxn= -+5, inf=0x7fffffff;5 intN,m,cnt=1;6 intLVL[MAXN],ITR[MAXN],HEAD[MAXN];7 structedge{8 intTo,cap,next;9 Edge () {}TenEdgeintTo,intCapintnext): To, Cap (CAP), next (next) {} One}g[maxn*maxn*2]; A voidAdd_edge (intUintVintcap) { -G[++cnt]=edge (V,cap,head[u]); head[u]=CNT; -G[++cnt]=edge (U,0, Head[v]); head[v]=CNT; the } - voidBFsints) { -memset (lvl,-1,sizeofLVL); -lvl[s]=0; +Queue <int>Q; - Q.push (s); + while(!Q.empty ()) { A intu=Q.front (); Q.pop (); at for(intI=head[u];i;i=G[i].next) { - intv=g[i].to; - if(lvl[v]<0&&g[i].cap>0){ -lvl[v]=lvl[u]+1; - Q.push (v); - } in } - } to } + intDfsintUintTintf) { - if(u==t)returnF; the for(int&i=itr[u];i;i=G[i].next) { * intv=g[i].to; $ if(g[i].cap>0&&lvl[u]<Lvl[v]) {Panax Notoginseng intD=Dfs (V,t,min (f,g[i].cap)); - if(d>0){ theg[i].cap-=D; +g[i^1].cap+=D; A returnD; the } + } - } $ return 0; $ } - intMax_flow (intSintt) { - intflow=0; the for(BFS (s);lvl[t]>0; BFs (s)) { - for(intI=0; i<=n+1; i++) itr[i]=Head[i];Wuyi intF; the while((F=dfs (s,t,inf)) >0) flow+=F; - } Wu returnflow; - } About voidinit () { $scanf"%d%d",&n,&m); - for(intI=1; i<=m;i++) Add_edge (0I1); - for(inti=m+1; i<=n;i++) Add_edge (i,n+1,1); - intu,v; A while(SCANF ("%d%d", &u,&v)!=eof) Add_edge (U,v,1); + } the intMain () { -Freopen ("flyer.in","R", stdin); $Freopen ("Flyer.out","W", stdout); the init (); theprintf"%d\n", Max_flow (0, n+1)); the fclose (stdin); the fclose (stdout); - return 0; in}
View Code
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.out4
Cogs_14_ with Pilots _ (binary graph matching + maximum flow, network flow 24 questions #01)