hdu_2444 the accomodation of Students-two minute figure + maximum match

Source: Internet
Author: User

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

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.