#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 210;
int match[maxn];
int line[maxn][maxn];
int vis[maxn];
int N , M;
int find(int start)
{
for(int i = 1;i <= M;i++)
{
if(!vis[i]&&line[start][i])
{
vis[i] = 1;
if(match[i] == -1 || find(match[i]))
{
match[i] = start;
return 1;
}
}
}
return 0;
}
void Match()
{
memset(match, -1 , sizeof(match));
int ans=0;
for(int i = 1;i <= N;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
ans++;
}
printf("%d\n",ans);
}
int main()
{
while(scanf("%d%d" , &N , &M)!=EOF)
{
memset(line,0,sizeof(line));
for(int i = 1;i <= N;i++)
{
int num;
scanf("%d" , &num);
while(num--)
{
int v;
scanf("%d", &v);
line[i][v]=1;
}
}
Match();
}
return 0;
}
时间: 2024-12-04 21:38:10