Hdu2063 _ roller coaster (bipartite chart/maximum matching)

Source: Internet
Author: User

Solution report

Question Portal

Question:

Find the maximum number of matching men and women.

Ideas:

Simple maximum matching.

#include <cstdio>#include <cstring>#include <iostream>using namespace std;int k,n,m,mmap[1100][1100],vis[550],pre[550];int dfs(int x){    for(int i=1;i<=n;i++){        if(!vis[i]&&mmap[x][i]) {            vis[i]=1;            if(pre[i]==-1||dfs(pre[i])){                pre[i]=x;                return 1;            }        }    }    return 0;}int main(){    int i,j,u,v;    while(~scanf("%d",&k))    {        if(!k)break;        memset(pre,-1,sizeof(pre));        memset(mmap,0,sizeof(mmap));        scanf("%d%d",&m,&n);        for(i=0;i<k;i++){            scanf("%d%d",&u,&v);            mmap[u][v]=1;        }        int ans=0;        for(i=1;i<=m;i++){            memset(vis,0,sizeof(vis));            ans+=dfs(i);        }        printf("%d\n",ans);    }}

Roller coaster Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 10858 accepted submission (s): 4782


Problem descriptionrpg girls went to the playground today and finally got on the coveted roller coaster. However, there are only two seats in each row of the roller coaster, and there is an unwritten rule, that is, every girl must find a boy as a partner and sit with her. However, every girl has her own ideas. For example, rabbit is only willing to be a partner with xhd or pqk. Grass is only willing to be a partner with linle or ll, princesssnow is willing to be a partner with the water prodigal son or pseudo cool. Considering the funding issue, boss Liu decided to let the partner find a ride on the roller coaster. Other people, hey, just stand and watch it. Smart acmer, can you help calculate how many combinations can ride on a roller coaster?
The first line of input data is a three integer K, M, N, indicating the number of possible combinations, the number of girls, and the number of boys. 0 <k <= 1000
1 <= N and M <= 500. In the next K rows, each row has two numbers, indicating that female AI is willing to be partner with boys' BJ. The last 0 end input.
Output outputs an integer for each group of data, indicating the maximum number of combinations that can be used on a roller coaster.
Sample Input
6 3 31 11 21 32 12 33 10
 
Sample output
3
 
Authorprincesssnow

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.