hdu:2063 roller Coaster (two-figure maximum match)

Source: Internet
Author: User
Tags time limit

Roller coaster

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 16791 Accepted Submission (s): 7334

Problem Description
RPG Girls today and we go to the amusement park to play, finally can sit on the dream of the roller coaster. However, the roller coaster in each row only two seats, and there is an unwritten rule, is that every girl must find all the boys do partner and her sitting. However, each girl has their own ideas, for example, rabbit only willing and xhd or pqk do Partner,grass only willing and linle or ll do partner,princesssnow willing and water prodigal or pseudo-queer do partner. Considering the financial problems, boss Liu decided to only find partner people to ride the roller coaster, other people, hey, just stand down and watch it. Smart Acmer, you can help calculate the maximum number of pairs can sit on the roller coaster.

Input
The first line of input data is three integers k, M, N, respectively, indicating the number of possible combinations, the number of females, and the number of males. 0

#include <stdio.h> #include <string.h> int map[1500][1500];//map[i][j] Mark I and J have ambiguous ...
int vis[1500];//Marks whether the boy is visited int link[1500];//to represent whether the boys are selected int n,m,k;
        bool Dfs (int x) {for (int i=1;i<=n;i++) {if (!vis[i]&&map[x][i]==1)//is not accessed, and two people have ambiguous. {vis[i]=1;//tag has been accessed if (!link[i]| |
                DFS (Link[i])//Boy I was not picked or picked boys I girl can also pick other boys {link[i]=x;
            return true;
}}} return false;
        } int main () {while (scanf ("%d", &k)!=eof) {if (k==0) break;
        scanf ("%d%d", &m,&n);
        int ans=0;
        memset (map,0,sizeof (map));
        memset (link,0,sizeof (link));
            while (k--) {int girl,boy;
            scanf ("%d%d", &girl,&boy);
        Map[girl][boy]=1;
            } for (int i=1;i<=m;i++) {memset (vis,0,sizeof (VIS));
        if (Dfs (i)) ans++; } printf ("%D\n ", ans);
} 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.