抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

题目传送门

思路

这是个板子题,二分图的最小点覆盖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
using namespace std;
int e[500][500], n, m, match[500], ans, book[500], cow[500];
int dfs(int u){
for (int i = 1; i <= m; i++){
if (e[u][i] == 1 && book[i] == 0){
book[i] = 1;
if (match[i] == 0 || dfs(match[i]) == 1){
match[i] = u;
return 1;
}
}
}
return 0;
}
int main(){
int t, x, p;
cin >> n >> m >> p;
for (int i = 1; i <= p; i++){
cin >> t >> x;
e[t][x] = 1;
}
for (int i = 1; i <= n; i++){
memset(book, 0, sizeof(book));
if (dfs(i) == 1) ans ++;
}
cout << ans << endl;
return 0;
}

评论