제목 링크 : Ollivanders : Makers of Fine Wands since 382 BC.
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int maxn=111;
vector<int> g[maxn<<2];
bool vis[maxn];
int tag[maxn];
int n,m;
bool dfs(int x)
{
for(auto i:g[x])
{
if(vis[i]) continue;
vis[i]=true;
if(tag[i]==-1 || dfs(tag[i])) {tag[i]=x;return true;}
}
return false;
}
int rua()
{
int ans=0;
memset(tag,-1,sizeof(tag));
for(int i=0;i<111;i++) g[i].clear();
for(int i=1;i<=m;i++)
{
int k;scanf("%d",&k);
while(k--)
{
int x;scanf("%d",&x);
g[i].pb(x);
}
}
for(int i=1;i<=m;i++)
{
memset(vis,false,sizeof(vis));
if(dfs(i)) ans++;
}
return ans;
}
int main()
{
while(~scanf("%d%d",&n,&m)) printf("%d\n",rua());
return 0;
}