AcWing 1394. 完美牛棚
原题链接
中等
作者:
不是谁的兰
,
2023-09-19 22:46:06
,
所有人可见
,
阅读 74
C++ 代码
#include <iostream>
#include <cstring>
using namespace std;
const int N = 210;
bool g[N][N];
bool st[N];
int match[N];
int n,m;
bool find(int x)
{
for(int i=1;i<=m;i++)
{
if(st[i]==false&&g[x][i])
{
st[i]=true;
if(match[i]==0||find(match[i]))
{
match[i]=x;
return true;
}
}
}
return false;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
int cnt;
cin>>cnt;
while(cnt--)
{
int x;
cin>>x;
g[i][x]=true;
}
}
int res=0;
for(int i=1;i<=n;i++)
{
memset(st,0,sizeof st);
if(find(i)) res++;
}
cout<<res<<endl;
}