Minimum vertex overlay for a binary graph: with a minimum of points, each edge is associated with at least one point.
Maximum number of matches = minimum point coverage (Konig theorem)
Water problem ...
Suddenly found my previous Hungarian algorithm template has a problem ... Because here the point on the left is 1~n, the point on the right is 1~m, so there are different points marking is the same, pay attention!
Because the algorithm itself is O (n^2), so the data will not be very large, rest assured with the adjacency matrix to save it ...
If a side has 0, then do not need to add in, each product should only appear once, otherwise it is wrong ... I thought for a long time, because the topic did not say that each product only appears once ...
Hdu1150#include <cstdio> #include <cstring> #include <iostream> using namespace std ; const int n = 105;int n, m, K;bool mp[n][n];int match[n];bool used[n];bool find (int u) {for (int v = 0; v < m; ++v) {i F (Mp[u][v] &&!used[v]) {Used[v] = true;if (Match[v] = = 1 | | find (MATCH[V])) {Match[v] = U;return true;}} return false;} int Hungary () {memset (match,-1, sizeof match), int ans = 0;for (int i = 0; i < n; ++i) {memset (used, false, sizeof used ); if (find (i)) ++ans;} return ans;} int main () {//freopen ("in", "R", stdin) and while (~SCANF ("%d", &n) && N) {scanf ("%d%d", &m, &k); int u, v; Memset (MP, false, sizeof MP), while (k--) {scanf ("%*d%d%d", &u, &v), if (!u | |!v) CONTINUE;MP[U][V] = true;} printf ("%d\n", Hungary ());} return 0;}
Hdu1150-machine Schedule (minimum point coverage)