Test instructions: First judge whether the students can be divided into two pieces of mutual understanding of the collective, and then find the two collective best match
Spit Groove: The fan wa a few times, and then judge whether it is a binary graph function written in the outside on the OK.
/************************************************author:D arktongcreated time:2016/8/1 13:02:46File name:h du_2444.cpp*************************************************///#include <bits/stdc++.h>#include <cstdio>#include<cstring>#include<queue>using namespacestd;Const intMAXN = $+Ten;intW[MAXN][MAXN], N, m;intLEFT[MAXN];BOOLUSED[MAXN];BOOLMatchinti) { for(intj=1; j<=m;++j)if(w[i][j]&&!Used[j]) {Used[j]=true; if(! left[j]| |match (Left[j])) {Left[j]=i; return true; } } return false;}//returns the maximum number of matchesintHungary () {intres=0; Memset (left,0,sizeof(left)); for(intI=1; i<=n;++i) {memset (used,0,sizeof(used)); if(Match (i)) res++; } returnRes;}intVIS[MAXN];BOOLBFs () {memset (Vis,0,sizeof(VIS)); for(intI=1; i<=n;++i) {if(!Vis[i]) {Queue<int>Q; Q.push (i); Vis[i]=1; while(!Q.empty ()) { intt =Q.front (); Q.pop (); for(intj=1; j<=n;++j) {if(W[t][j]) {if(Vis[j]==vis[t])return false; Else if(vis[j]==0) {Vis[j]= -Vis[t]; Q.push (j); } } } } } } return true;}intMain () {intT, cas=1, K; while(SCANF ("%d%d", &n, &k) = =2) {memset (W,0,sizeof(w)); memset (Vis,0,sizeof(VIS)); M=N; intu, v; for(intI=1; i<=k;++i) {scanf ("%d%d", &u, &v); W[v][u]= w[u][v]=1; } if(!BFS ()) {Puts ("No"); Continue; } intAns =Hungary (); printf ("%d\n", ans>>1); } return 0;}
hdu_2444 the accomodation of Students-two minute figure + maximum match