You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
921 B
46 lines
921 B
#include <cstdio>
|
|
#include <cstring>
|
|
using namespace std;
|
|
const int N = 550;
|
|
|
|
int g[N][N]; // 地图
|
|
int n, m;
|
|
|
|
// 匈牙利
|
|
int st[N], match[N];
|
|
int dfs(int u) {
|
|
for (int i = 1; i <= n; i++) {
|
|
if (g[u][i] && !st[i]) { // u->i有边
|
|
st[i] = 1;
|
|
if (match[i] == -1 || dfs(match[i])) {
|
|
match[i] = u;
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
int main() {
|
|
#ifndef ONa_JUDGE
|
|
freopen("POJ3041.in", "r", stdin);
|
|
#endif
|
|
memset(g, 0, sizeof g);
|
|
memset(match, -1, sizeof match);
|
|
scanf("%d%d", &n, &m);
|
|
|
|
while (m--) {
|
|
int x, y;
|
|
scanf("%d%d", &x, &y);
|
|
g[x][y] = 1;
|
|
}
|
|
|
|
// 匈牙利
|
|
int res = 0;
|
|
for (int i = 1; i <= n; i++) {
|
|
memset(st, 0, sizeof st);
|
|
if (dfs(i)) res++;
|
|
}
|
|
// 输出
|
|
printf("%d\n", res);
|
|
return 0;
|
|
} |