# HPU1179 Ollivanders:makers of Fine wands since 382 BC. "Binary graph Max Match"

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1179

Main topic:

The title is too long, the simple meaning is: There are n wands, M wizards, wands have a number of matching wizards. But a magician.

Only one wand can be matched. So the question is: how many magicians can get the magic wand at most.

Ideas:

Make a dichotomy, one side is a wand, the other is a magician. The corresponding match as the side of the binary graph. Using the Hungarian algorithm, find out two

What is the maximum matching of the graph?

AC Code:

`#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace std;const int maxn = 110;bool map[maxn][maxn],mask[maxn];int n,m,cx[maxn],cy[maxn];int FindPath (int u) {for (int i = 1; I <= M;            ++i) {if (Map[u][i] &&!mask[i]) {mask[i] = 1; if (cy[i] = =-1 | |                Findpath (Cy[i])) {Cy[i] = u;                Cx[u] = i;            return 1; }}} return 0;}    int Maxmatch () {int ret = 0;    for (int i = 1; I <= N; ++i) cx[i] = 1;    for (int i = 1; I <= M; ++i) cy[i] = 1;                for (int i = 1; I <= N, ++i) {if (cx[i] = = 1) {for (int j = 1; j <= M; ++j)            MASK[J] = 0;        RET + = Findpath (i); }} return ret;}    int main () {int d,w;        while (~SCANF ("%d%d", &n,&m)) {memset (map,false,sizeof (MAP));      for (int i = 1; I <= M; ++i) {      scanf ("%d", &d);                while (d--) {scanf ("%d", &w);            Map[w][i] = 1;    }} printf ("%d\n", Maxmatch ()); } return 0;}`

HPU1179 Ollivanders:makers of Fine wands since 382 BC. "Binary graph Max Match"

Related Keywords:

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.