最小覆盖点问题 可以转换成二分图的最大匹配
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
bool map[600][600];
bool book[600];
int Search[600];
int v1, v2;
bool dfs(int x)
{
for(int i = 1;i <= v2;i++){//集合v2
if(map[x][i]&&!book[i]){
book[i] = true;
if(Search[i]==0||dfs(Search[i])){
Search[i] = x;
return true;
}
}
}
return false;
}
int main()
{
int n, k;
cin >> n >> k;
int i;
v1 = v2 = n;
int a, b;
for(i = 1;i <= k;i++){
scanf("%d %d", &a, &b);
map[a][b] = true;
}
int cnt = 0;
for(i = 1;i <= v1;i++){//集合v1
memset(book,false,sizeof(book));
if(dfs(i)){
cnt++;
}
}
printf("%d\n", cnt);
return 0;
}