#include<bits/stdc++.h> using namespace std; const int N = 550, M = 1e5 + 10; int n1, n2, m, h[N], e[M], ne[M], idx; int match[N], ans; bool vis[N]; void addEdge(int f, int t) { e[idx] = t, ne[idx] = h[f], h[f] = idx ++ ; } bool find(int u) { for(int i = h[u]; ~i; i = ne[i]) { int j = e[i]; if(!vis[j]) { vis[j] = true; if(!match[j] || find(match[j])) { match[j] = u; return true; } } } return false; } int main() { cin >> n1 >> n2 >> m; memset(h, -1, sizeof h); for(int i = 0; i < m; i ++ ) { int f, t; cin >> f >> t; addEdge(f, t); } for(int i = 1; i <= n1; i ++ ) { memset(vis, false, sizeof vis); if(find(i)) ans ++ ; } cout << ans << endl; return 0; }
标签:idx,int,匈牙利,ne,vis,算法,addEdge,match From: https://www.cnblogs.com/leyuo/p/16650194.html