#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define SIZE 505
int n;
int graph[SIZE][SIZE];
int visited[SIZE];
int match[SIZE];
int Hungary(int u){
int i;
for(i = 0; i < n; i++){
if(!visited[i] && graph[u][i]){
visited[i] = 1;
if(match[i] == -1 || Hungary(match[i])){
match[i] = u;
return 1;
}
}
}
return 0;
}
int main(){
//freopen("in.txt", "r", stdin);
while(cin>>n){
int i, j;
memset(graph, 0, sizeof(graph));
memset(match, -1, sizeof(match));
for(i = 0; i < n; i++){
int stu, knowN, tmp_know;
scanf("%d: (%d)", &stu, &knowN);
for(j = 0; j < knowN; j++){
cin>>tmp_know;
graph[i][tmp_know] = 1;
}
}
int ans = 0;
for(i = 0; i < n; i++){
memset(visited, 0, sizeof(visited));
if(Hungary(i))
ans++;
}
cout<<n - ans / 2<<endl; //除2很关键,因为算了两遍
}
return 0;
}
zoj 1137 Girls and Boys 二分图的最大独立集
最新推荐文章于 2022-05-28 23:57:50 发布