把激光看做点,星星看做边建图
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 1010;
int n, m;
vector<int> G[maxn];
int match[maxn];
bool used[maxn];
void addedge(int u, int v) {
G[u].push_back(v);
G[v].push_back(u);
}
bool dfs(int u) {
used[u] = true;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (match[v] < 0 || (!used[match[v]] && dfs(match[v]))) {
match[v] = u;
return true;
}
}
return false;
}
int bipartite_matching() {
int res = 0;
memset(match, -1, sizeof(match));
for (int i = 1; i <= n; i++) {
if (match[i] < 0) {
memset(used, false, sizeof(used));
if (dfs(i)) res++;
}
}
return res;
}
int main() {
while (~scanf("%d %d", &n, &m)) {
for (int i = 0; i <= (n<<1); i++) G[i].clear();
for (int i = 0; i < m; i++) {
int x, y;
scanf("%d %d", &x, &y);
addedge(x, y + n);
}
printf("%d\n", bipartite_matching());
}
return 0;
}