Ollivanders: Makers of Fine Wands since 382 BC. HDU

#include <bits/stdc++.h>
using namespace std;
const int N=510,M=100010;
int e[M],ne[M],h[N],idx,ans;
bool st[N];
int n,m,num,a;
int match[N];
void add(int a,int b) {
	e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
int find(int x) {
	for(int i=h[x]; i!=-1; i=ne[i]) {
		int j=e[i];
		if(!st[j]) {
			st[j]=true;
			if(match[j]==0||find(match[j])) {
				match[j]=x;
				return true;
			}
		}
	}
	return false;
}
int main() {
	while(~scanf("%d%d",&n,&m)) 
	{
		memset(match,0,sizeof match);
		memset(h,-1,sizeof h);
		idx=0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d",&num);
			while(num--)
			{
				scanf("%d",&a); 
				add(i,a);
			}
		} 
		ans=0;
		for(int i=1; i<=m; i++) {
			memset(st,false,sizeof st);
			if(find(i)) ans++;
		}
		printf("%d
",ans);
	}
	return 0;
}Ollivanders: Makers of Fine Wands since 382 BC. HDU - 1179 
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12398700.html