Poj3041-Asteroids, minimum vertex overwrite = maximum number of matching, minimum vertex Overwrite
Click Open Link
Minimum vertex overwrite in a bipartite graph = maximum number of matching in a Bipartite Graph
N * N networks contain K minor planets. The position of the minor I is (Ri, Ci ). There is now a powerful weapon that can use a single beam to destroy an entire row or a whole column of minor planets. How many light beams are required to use this weapon to destroy all the minor planets?
Analysis: a bipartite graph is created based on the coordinates of the left and right sides of the Minor Planet. We can see that the minimum vertex overwrite Number of the Bipartite Graph is obtained.
# Include <cstdio> # include <cstring> # include <vector> # include <algorithm> using namespace std; const int maxn = 500 + 5; // maximum number of single-side vertices struct BPM {int n, m; // Number of left and right vertices vector <int> G [maxn]; // adjacent table int left [maxn]; // left [I] indicates the matching point number of point I on the right.-1 indicates that bool T [maxn] does not exist. // T [I] indicates whether int right [maxn] has been marked for point I on the right; // calculates bool S [maxn] for minimum overwrite; // use void init (int n, int m) {this-> n = n; this-> m = m; for (int I = 0; I <n; ++ I) G [I]. clear ();} Void AddEdge (int u, int v) {G [u]. push_back (v);} bool match (int u) {S [u] = true; for (int I = 0; I <G [u]. size (); ++ I) {int v = G [u] [I]; if (! T [v]) {T [v] = true; if (left [v] =-1 | match (left [v]) {left [v] = u; right [u] = v; return true ;}}return false;} // returns the maximum matching int solve () {memset (left, -1, sizeof left); memset (right,-1, sizeof right); int ans = 0; for (int u = 0; u <n; ++ u) {// extended memset (S, 0, sizeof S) from the left node u; memset (T, 0, sizeof T); if (match (u )) ans ++;} return ans ;}// obtain the minimum coverage. Int mincover (vector <int> & X, vector <int> & Y) {int ans = solve (); memset (S, 0, sizeof S); for (int u = 0; u <n; ++ u) if (right [u] =-1) match (u ); // extended for (int u = 0; u <n; ++ u) if (! S [u]) X. push_back (u); // The unlabeled point in X for (int v = 0; v <m; ++ v) if (T [v]) Y. push_back (v); // The marked point in Y: return ans ;}}; BPM solver; int main () {int I, j, n, k; scanf ("% d", & n, & k); solver. init (n, n); for (I = 0; I <k; ++ I) {int x, y; scanf ("% d", & x, & y); x --; y --; solver. addEdge (x, y); // directed graph} int ans = solver. solve (); printf ("% d \ n", ans); return 0 ;}
Minimum vertex overwrite = proof of maximum binary matching?
For example, the maximum matching value is M. To obtain the least vertex, each edge must be associated with at least one vertex in the period.
M points are sufficient. That is to say, after they cover the M edge with the largest matching, if some side e is not covered, then after adding e to it, a larger matching result will appear, causing a conflict.
M points are required. Because there are no common vertices for the matching M edges, at least M vertices can be overwritten.
Reference: lrj black book
In graph theory, the minimum coverage of an undirected graph solution is obtained by matching x with the maximum number of vertices n-x.
This DFS is the hungray algorithm that finds the largest matching. You will know it at Baidu.