#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MAXN=1500+10;
const int MAXM=1500*10;
struct Edge
{
int to,next;
} edge[MAXM];
int head[MAXN],tot,mx[MAXN],cx[MAXN],cy[MAXN],mk[MAXN];
void addedge(int from,int to)
{
edge[tot].to=to;
edge[tot].next=head[from];
head[from]=tot++;
}
void init()
{
memset(head,0xff,sizeof(head));
tot=0;
}
int dfs(int u)
{
for(int i=head[u]; i!=-1; i=edge[i].next)
{
int v=edge[i].to;
if(!mk[v])
{
mk[v]=1;
if(cy[v]==-1||dfs(cy[v]))
{
cx[u]=v;
cy[v]=u;
return 1;
}
}
}
return 0;
}
int Maxmatch(int n)
{
int res=0;
memset(cx,0xff,sizeof(cx));
memset(cy,0xff,sizeof(cy));
for(int i=1; i<=n; i++)
{
if(cx[i]==-1)
{
memset(mk,0,sizeof(mk));
res+=dfs(i);
}
}
return res;
}
int main()
{
int _,n,m,i,j,u,v;
while(~scanf("%d",&n))
{
init();
for(i=0;i<n;i++)
{
scanf("%d:(%d)",&u,&m);
for(j=0;j<m;j++)
{
scanf("%d",&v);
addedge(u+1,v+1);
addedge(v+1,u+1);
}
}
printf("%d\n",Maxmatch(n)/2);
}
return 0;
}
hdu 1054 Strategic Game 最小点覆盖集
最新推荐文章于 2023-08-04 19:39:54 发布