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 ;}