HDU 1150 Machine Schedule (classic binary match)

Source: Internet
Author: User

Group A n person B group M person//MAX How many people match each person just once # include<stdio.h># include<string.h># include<algorithm>using namespace Std;int n,m,k;int pp[1100][1100],map[1100],vis[1100];int bfs (int x)//dichotomy matching template {for (int i=1;i<=m;i++)// People in Group B to cater for match {if (!vis[i]&&pp[x][i]) {vis[i]=1;if (!map[i]| | BFS (Map[i]))//b I have not matched or matched the number in Group A (Map[i]) can also find other people to match {Map[i]=x;return 1;}} return 0;} int main () {int count,i,a,b,c;while (~scanf ("%d", &n), N) {memset (pp,0,sizeof (PP)),//Match memset (map,0,sizeof (map) ); scanf ("%d%d", &m,&k); for (i=0;i<k;i++) {scanf ("%d%d%d", &a,&b,&c)    ; Pp[b][c]=1;} count=0;//matches the number of    people in the for (i=1;i<=n;i++)//a group to match {memset (vis,0,sizeof (VIS)), if (BFS (i)) count++;} printf ("%d\n", count);} return 0;}

HDU 1150 Machine Schedule (classic binary 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.