Ollivanders:makers of Fine Wands since 382 BC.
Time limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)
Total submission (s): 1314 Accepted Submission (s): 718
Problem Description
In Diagon Alley, there are only one wand-seller,peeling gold letters over the door read ollivanders:makers of Fine wands s Ince 382 BC. A single wand lay on a faded purple cushion in the dusty window.
A tinkling bell rang somewhere in the depths of the shop as they stepped inside. It is a tiny place,empty execpt for a single spindly chair which Hagrid sat in to wait. Harry felt strangely as though he had entered a very strict library;he swallowd a log of new questions which had just OCCU Rred to him and looked instead in the thousands of narrow boxes piled neatly right up to the ceiling. For some reason,the back of the his neck prickled. The very dust and silence in this seemed to tingle with some secret magic.
' Good afternoon, ' said a soft voice. Harry jumped. Hagrid must has jumped,too,because there was a loud crunching noise and he got quickly off the spindly chair.
The standing before them, he wide pale eyes shining like moons through the gloom of the shop.
' Hello, ' said Harry awkwardly.
' Ah Yes, ' said the man. ' Yes,yes. I thought I ' d is seeing you soon,harry Potter. ' It wasn ' t a question. You have your mother ' s eyes. It seems only yesterday she is in this herself,buying her first wand. Ten and a quarter inches long, swishy, made of willow. Nice wand-charm work. '
Mor Ollivander moved closer to Harry.harry wished he would blink. Those sivery eyes were a bit creepy.
' Your father, on the other hand, favoured a mahogany wand. Eleven inches. Pliable.a little more power and excellent for Transfiguration. Well, I say your father favoured It-it's really the wand that choosed the wizard, of Cource. '
Yes, some wands fit some wizards, as we all know. But what Harry doesn ' t know was Ollivander had met a big trouble. That's more than twenty years Ago,when Harry's father James Potter was still a student in hogwarts.he went Diagon Alley to Buy new books,passing by Ollivander ' s shop. Ollivander was crazy for a problem:he is too busy to choose most suitable wand for every wizard. Even More,there is too many customer that day. Though Ollivader knew every wand ' s favourite,he could not choose as many wizards as possible to get the wands. So James potter,a very clever mans, gave him a magic disk with your program, to help him sell wands as many as possible.
Please Notice:one wand can is sold to the one wizard, and one wizard can only buy one wand,too.
Input
There is several cases. For each case, there is a integers n and m in the first Line,which mean there is N wizards and M wands (0 < n <= m <= 100).
Then M. lines contain the choices of each wand. The first integer in i+1th line was ki,and after these there was Ki integers bi,j which is the wizards who fit that wand. (0<=ki<=n,1<=bi,j<=n)
Output
Only one integer,shows how many wands Ollivander can sell.
Sample Input
3 4
3 1 2 3
1 1
1 1
0
Sample Output
2
There are n wizards, there are M. Wizards. Each sorcerer's wand is suitable for a certain sorcerer.
Here is the wizard's code for wizards:
/*#include <cstdio>#include <cstring>#include <algorithm>using namespace Std;intmatch[ $],e[205][205],book[205],n,m;intDfsintu) { for(intI=1; i<=m; i++) {if(book[i]==0&&e[u][i]==1) {book[i]=1;if(match[i]==-1|| DFS (i) = =1) {match[i]=u;return 1; } } }return 0;}intMain () { while(~SCANF ("%d%d",&n,&m) {memset (E,0, sizeof (e)); memset (match,-1, sizeof (match));intT1,t2; for(intI=1; i<=m; i++) {scanf ("%d", &T1); for(intj=0; j<t1; J + +) {scanf ("%d", &T2); e[t2][i]=1; } }intsum=0;//memset(Book,0, sizeof (book)); for(intI=1; i<=n; i++) {if(Dfs (i)) {memset (book,0, sizeof (book)); sum++; } }printf("%d\ n", sum); }return 0;} /*#include <stdio.h>#include <string.h>int Map[ the][ the],last_y[ the],hav[ the],n,m;intFindmax (int m);intMain () {intI,j,a,b,sum; while(SCANF ("%d %d", &n,&m)!=eof) {memset (Map,0, sizeof (Map)); memset (last_y,-1, sizeof (last_y)); sum=0; for(i=1; i<=m;i++) {scanf ("%d", &a); for(j=0; j<a;j++) {scanf ("%d", &b);Map[b] [i]=1; } } for(i=1; i<=n;i++) {if(Findmax (i)) {memset (hav,0, sizeof (HAV)); sum++; } }printf("%d\ n", Sum); }return 0;}intFindmax (int m){intI for(i=1; i<=m;i++) {if(!hav[i]&&Map[m][i]) {hav[i]=1;if(last_y[i]==-1|| Findmax (Last_y[i])) {last_y[i]=m;return 1; } } }return 0;}*/#include <cstdio>#include <cstring>#include <algorithm>using namespace Std;intmatch[ $],e[ $][ $],book[ $],n,m;intDfsintu) { for(intI=1; i<=n;i++) {if(book[i]==0&&e[u][i]==1) {book[i]=1;if(match[i]==0|| DFS (Match[i])) {match[i]=u;return 1; } } }return 0;}intMain () { while(~SCANF ("%d%d",&n,&m) {memset (E,0, sizeof (e)); memset (book,0, sizeof (book)); memset (Match,0, sizeof (match));intT1,t2; for(intI=1; i<=m; i++) {scanf ("%d", &T1); for(intj=0; j<t1;j++) {scanf ("%d", &T2); e[i][t2]=1; } }intsum=0; for(intI=1; i<=m; i++) {memset (book,0, sizeof (book));if(Dfs (i)) {sum++; } }printf("%d\ n", sum); }return 0;}
HDU 1179 ollivanders:makers of Fine wands since 382 BC. (binary graph matching--Hungarian algorithm)