Time Limit: 7000MS | Memory Limit: 65536K | |
Total Submissions: 3040 | Accepted: 953 |
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
Source
没什么好说的,就是二分+多重匹配
一Y,不错
#include<cstdio>
#include<cstring>
int n,m;
bool mat[1001][501],used[501];
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 check()
{
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 find()
{
int low=1,high=n;
int ans=high;
while(low<high)
{
mid=(low+high)>>1;
if(check())
{
if(mid<ans) ans=mid;
high=mid;
}
else low=mid+1;
}
return ans;
}
int main()
{
char str[20];
int x;
char c;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0) break;
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;
}
}
printf("%d/n",find());
}
return 0;
}