[Bipartite graph multi-match] poj 2289

Source: Internet
Author: User

Improved Hungary water over Ms ....

# Include <map> # include <set> # include <list> # include <queue> # include <deque> # include <stack> # include <string> # include <cstdio> # include <math. h> # include <iomanip> # include <cstdlib> # include <limits. h> # include <string. h> # include <iostream> # include <fstream> # include <algorithm> using namespace STD; # define ll long # define Min-99999999 # define Max 99999999 # define PII pair <int, int> # define bug cout <"He Re !! "<Endl # define PI ACOs (-1.0) # define fre freopen (" input.txt "," r ", stdin) # define FF freopen (" output.txt "," W ", stdout) # define EPS 1e-8 # define n 233 char STR [101]; int match [505] [1005]; // group number on the left, the right side is the number one int CNT [505]; int vis [505]; int G [505] [1005]; int n, m; int mid; bool sear (int s) {int I, j; for (I = 0; I <m; I ++) {If (G [I] [s] &! Vis [I]) {vis [I] = 1; if (CNT [I] <mid) {match [I] [CNT [I] ++] = s; return true;} else {for (j = 0; j <CNT [I]; j ++) {If (SEAR (Match [I] [J]) {match [I] [J] = s; return true ;}}}return false;} bool chk (INT mid) {int I, j; memset (CNT, 0, sizeof (CNT); for (I = 0; I <n; I ++) {memset (VIS, 0, sizeof (VIS); If (! Sear (I) return false;} return true;} void Gao () {int I, j; int L = 0, r = 1000; // binary answer while (L <r) {mid = (L + r)> 1; if (chk (MID) {r = mid ;} else l = Mid + 1;} printf ("% d \ n", L);} int main () {While (scanf ("% d", & N, & M) & (n + M) {// number of people, number of groups int I, j; getchar (); memset (G, 0, sizeof (g )); for (I = 0; I <n; I ++) {gets (STR); int Len = strlen (STR); For (j = 0; j <Len ;) {While (STR [J] <'0' | STR [J]> '9') {J ++;} int TMP = 0; while (STR [J]> = '0' & STR [J] <= '9') {TMP = TMP * 10 + STR [J]-'0 '; j ++;} G [TMP] [I] = 1; // each TMP group has multiple I} Gao ();} return 0 ;}

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.