Description
Input
Output
Sample Input
3 2 John 0 1 Rose 1 Mary 1 5 4 ACM 1 2 3 ICPC 0 1 Asian 0 2 3 Regional 1 2 ShangHai 0 2 0 0
Sample Output
2 2
//
#include<cstdio>
#include<cstring>
int n,m;//X和Y
bool mat[1001][501],used[501];//mat初始清零
int link[1001][501];
int mid;
bool can(int t)
{
for(int i=1;i<=m;i++)
{
if(!used[i]&&mat[t][i])
{
used[i]=1;
if(link[i][0]<mid)
{
link[i][++link[i][0]]=t;
return true;
}
else
{
for(int j=1;j<=link[i][0];j++)
if(can(link[i][j]))
{
link[i][j]=t;
return true;
}
}
}
}
return false;
}
bool Match()//X中所有点都匹配
{
for(int i=0;i<=m;i++) link[i][0]=0;
for(int i=1;i<=n;i++)
{
memset(used,false,sizeof(used));
if(!can(i)) return false;
}
return true;
}
int main()
{
char str[20];
int x;
char c;
while(scanf("%d%d",&n,&m)==2&&n)
{
memset(mat,false,sizeof(mat));
for(int i=1;i<=n;i++)
{
scanf("%s",str);
while(scanf("%d%c",&x,&c))
{
mat[i][x+1]=true;
if(c=='\n') break;
}
}
int low=1,high=n;
while(low<high)
{
mid=(low+high)>>1;
if(Match())
{
high=mid;
}
else low=mid+1;
}
printf("%d\n",high);
}
return 0;
}