HDU 1054

时间:2023-03-10 06:47:24
HDU 1054

http://acm.hdu.edu.cn/showproblem.php?pid=1054

二分图最少顶点覆盖,模板题,双向边最后结果/2

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std ;
struct node{
int s,t,nxt ;
}e[] ;
int head[],vis[],match[],cnt,n,m ;
int find(int s)
{
for(int i=head[s] ;i!=- ;i=e[i].nxt)
{
int tt=e[i].t ;
if(!vis[tt])
{
vis[tt]= ;
if(match[tt]==- || find(match[tt]))
{
match[tt]=s ;
return ;
}
}
}
return ;
}
int max_match()
{
int ans= ;
memset(match,-,sizeof(match)) ;
for(int i= ;i<n ;i++)
{
memset(vis,,sizeof(vis)) ;
ans+=find(i) ;
}
return ans ;
}
void add(int s,int t)
{
e[cnt].s=s ;
e[cnt].t=t ;
e[cnt].nxt=head[s] ;
head[s]=cnt++ ;
} int main(){
while(~scanf("%d%*c",&n)){
memset(head,-,sizeof(head));
cnt=;
for(int i=;i<n;i++){
int s;
scanf("%d%*c%*c%d%*c",&s,&m);
for(int j=;j<m;j++){
int t;
scanf("%d%*c",&t);
add(s,t);add(t,s);
}
}
printf("%d\n",max_match()/);
}
return ;
}